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

时间:2015-02-27 10:31:25

标签: swift watchkit

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

1 个答案:

答案 0 :(得分:5)

在AppDelegate中添加此方法:

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

在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")
}

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

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