我正在做一个示例项目,我喜欢将数据从iphone发送到WatchKit。我不知道该怎么做。任何帮助将不胜感激。提前致谢
答案 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
参数中的字典。