gpt4 book ai didi

ios - WatchConnectivity 试图将数据发送到 Watch 应用程序

转载 作者:行者123 更新时间:2023-11-29 00:04:41 30 4
gpt4 key购买 nike

我正在尝试将数据从我的 iOS 应用发送到 Watch 应用。我为此使用 updateApplicationContext。

我有一个在 NSDictionary 中转换的 json 文件并尝试发送它。但是有一个错误,这里是:

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

文件已正确读取。

现在这是尝试发送数据的代码。

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!");
}

我在某处读到我们可以发送的类型是有限的,但字典是允许的。不过我要寄一本字典。

你能找出错误是什么吗?

[解决方案]

我发现我的字典中有 long 类型的值。在我的 JSON 中,我有一些属性被转换为 long 类型。这是之前的属性之一:

"state": 0

我只是将数字放在字符串引号中。

"state":"0"

最佳答案

检查字典的内容。
WatchConnectivity 字典只能包含 property list types .

关于ios - WatchConnectivity 试图将数据发送到 Watch 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48454320/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com