如何在swift中将数据从iphone发送到watchkit

use*_*935 1 swift watchkit

我正在做一个示例项目,我喜欢将数据从iphone发送到WatchKit.我不知道该怎么做.任何帮助将不胜感激.提前致谢

Dej*_*dar 5

在AppDelegate中添加此方法:

func application(application: UIApplication!,
handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]!,
   reply: (([NSObject : AnyObject]!) -> Void)!)
{
   //define your dictionary
   reply(yourDict)
}
Run Code Online (Sandbox Code Playgroud)

将它添加到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")
}
Run Code Online (Sandbox Code Playgroud)

第一个函数将触发,WKInterfaceController.openParentApplication并将在reply参数中回复字典.

开发者论坛: https ://devforums.apple.com/message/1082689#1082689