gpt4 book ai didi

ios - 为什么方法 updateApplicationContext 返回 "Payload contains unsupported type."

转载 作者:行者123 更新时间:2023-11-28 10:55:38 25 4
gpt4 key购买 nike

我正在调用方法:

 open func updateApplicationContext(_ applicationContext: [String : Any]) throws

这需要 [String : Any]

我有返回的方法:

 func watchData() -> [String: Any] {
var dictionary = [String: Any]()
let wallets = Database.sharedInstance.database.objects(Wallet.self)
for wallet in wallets {
if let qrCode = QRCode(wallet.address) {
let watchWallet = WatchWallet(fund: wallet.fund, avaliable: wallet.avaliable, address: wallet.address, imageData: qrCode.PNGData)
dictionary[wallet.fund] = watchWallet
}
}
return dictionary
}

并且从 watchData() 返回的数据无效。

WatchWallet 是 strcut。

struct WatchWallet {
let fund: String
let avaliable: String
let address: String
let imageData: Data
}

我想知道我错过了什么。

方法错误:

无法发送应用程序上下文:错误域=WCErrorDomain 代码=7010“负载包含不受支持的类型。” UserInfo={NSLocalizedDescription=Payload 包含不受支持的类型。, NSLocalizedRecoverySuggestion=只传递有效类型。}

最佳答案

发件人:https://developer.apple.com/library/content/documentation/General/Conceptual/WatchKitProgrammingGuide/SharingData.html

For most types of transfers, you provide an NSDictionary object with the data you want to send. The keys and values of your dictionary must all be property list types, because the data must be serialized and sent wirelessly. (If you need to include types that are not property list types, package them in an NSData object or write them to a file before sending them.)

因此,字典是 [String: Any] 的事实具有误导性,因为 Any 值仅限于有效的属性列表类型。完整的类型列表在下面的文章中,但如您所料)包括基本类型、数组、字典和 NSData:

https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/PropertyLists/AboutPropertyLists/AboutPropertyLists.html

关于ios - 为什么方法 updateApplicationContext 返回 "Payload contains unsupported type.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43876138/

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