Creating ApplicationToken with Decoder from string

I've been working a lot with the FamilyControls API and App Shield recently but have encountered a problem with no documentation. I used the FamilyActivitySelection to select the app store to shield(This is just for testing), and then printed out the application token:

1wfY¸êBòS« öi#×(É?âðwù/jQ„¿ŠJžïE¢?€·¿œ•º<Òd?ýŠr7¥Ãn—NžátJ¹ÿ85B_{VAF’fC8.‰,,¸¯3 T7Fš±õü;‘Œ˜¹?v@¯ô›Ä\-õ#†Ò

I know the application token is a Codable object so I was wondering,

How do I create an application token using the Token<Application> initializer

init(from: any Decoder) throws
Creates a new instance by decoding from the given decoder.

Using the above data? Do I have to encode first in order to decode it?

For reference, the code I tried to use is:

            
            newValue.applicationTokens.encode(to: JSONEncoder)
            
            if let encoded = try? JSONEncoder().encode(newValue.applicationTokens) {
                data = encoded
                print(String(data: data, encoding: .utf8)!)
            }

            if let app = try? JSONDecoder().decode(Token<Application>.self, from: data) {
                let token = Application(token: app)
                print(token)
            } else {
                print("didn't work")
            }

But it prints didn't work every time.

What should I do differently?

Try this

if let app = try? JSONDecoder().decode(.decode(ApplicationToken.self, from: data) { let token = Application(token: app) print(token) } else { print("didn't work") }

Token<Application>.self changed to ApplicationToken.self

Creating ApplicationToken with Decoder from string
 
 
Q