我有一本字典
dict = [Int : Bool]我想知道是否有一种简单的方法可以将它从iPhone发送到watch,反之亦然,通过WatchConnectivity框架中的交互消息传递?
谢谢。
发布于 2015-10-23 15:28:19
你可以这样做:
if (WCSession.isSupported()) {
let session = WCSession.default
session.delegate = self
session.activate()
}
let dict = [Int : bool]
let message = ["message" : dict]
WCSession.default.sendMessage(message,
replyHandler: { (reply) -> Void in
},
errorHandler: { (error) -> Void in
}
)发布于 2015-10-23 13:42:54
在您的watchkit extention中编写以下代码:
func getDataFromParentApp(image: String) {
let dictionary = ["Desired Word":image]
WKInterfaceController.openParentApplication(dictionary) {
(replyInfo, error) -> Void in
}在AppDelegate中,编写如下一条:
func application(application: UIApplication!,
handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]!,
reply: (([NSObject : AnyObject]!) -> Void)!) {
getImageForWordThatRhymesWithDat(userInfo, reply)
}您可以参考这个链接。
https://stackoverflow.com/questions/33303622
复制相似问题