I am doing a sample project in which i like to send data from iphone to WatchKit. I have no idea of how to do this. Any help will be appreciated. Thanks in advance
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Add this method in the AppDelegate:
func application(application: UIApplication!,
handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]!,
reply: (([NSObject : AnyObject]!) -> Void)!)
{
//define your dictionary
reply(yourDict)
}
Add this anywhere in the Apple Watch Extension:
var dict = ["test" : 4] //your dictionary/request to sent to the iPhone
if !WKInterfaceController.openParentApplication(dict, reply: { (reply,error) -> Void in
println("\(reply)") //your reply data as Dictionary
}) {
println("ERROR")
}
The first function will trigger with WKInterfaceController.openParentApplication
and will reply the dictionary in the reply
parameter.
Developer forum: https://devforums.apple.com/message/1082689#1082689