简体   繁体   中英

WatchConnectivity attempting to send data to Watch app

I'm trying to send data from my iOS app to the Watch app. I'm using the updateApplicationContext for this.

I have a json file that I converted in NSDictionary and tried to send it. But there is an error, here it is:

[WCSession updateApplicationContext:error:]_block_invoke failed due to WCErrorCodePayloadUnsupportedTypes

The file is correctly read.

Now here is the code that tries to send the data.

NSString *fileName = [[NSBundle mainBundle] pathForResource:@"data"
                                                         ofType:@"json"];
    NSLog(fileName);
    if (fileName) {
        NSData *jsonData = [[NSData alloc] initWithContentsOfFile:fileName];
        NSDictionary *data = [NSJSONSerialization JSONObjectWithData:jsonData
                                                              options:0
                                                                error:&error];

        if (error) {
            NSLog(@"Something went wrong! %@", error.localizedDescription);
        }
        else {
            NSLog(@"Rsens info: %@", data);
            [WatchSessionManager.sharedManager updateApplicationContextWithApplicationContext:@{@"json": data} error:&error];
        }
    }
    else {
        NSLog(@"Couldn't find file!");
    }

I read somewhere that the types that we could send were limited, but the dictionary was allowed. I'm sending a dictionary though.

Can you find what is the error?

[SOLUTION]

I found out that there were values of type long in my dictionary. In my JSON I had some properties that were transtyped in type long. Here is one of the properties before:

"state": 0

I just put my numbers in string quotes.

"state":"0"

Check the dictionary's content.
WatchConnectivity dictionaries can only contain property list types .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM