我正在做一个示例项目,我想在其中将数据从 iphone 发送到 WatchKit。我不知道该怎么做。任何帮助将不胜感激。提前致谢
最佳答案
在 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
参数中回复字典。
关于swift - 如何快速将数据从iphone发送到watchkit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28762906/