我想从Apple watch按钮点击打开我的iPhone应用程序。我使用下面的代码来实现这一点,
在我的常量文件中,
let sharedUserActivityType = "com.mycompanyname.myappname.openApp"
let sharedIdentifierKey = "identifier"
在我的手表App控制器中:点击按钮,
updateUserActivity(sharedUserActivityType, userInfo: [sharedIdentifierKey : 123456], webpageURL: nil)
在我的iPhone AppDelegate中,
func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]!) -> Void) -> Bool {
if (userActivity.activityType == sharedUserActivityType) {
if let userInfo = userActivity.userInfo as? [String : AnyObject] {
if let identifier = userInfo[sharedIdentifierKey] as? Int {
//Do something
let alert = UIAlertView(title: "Handoff", message: "Handoff has been triggered for identifier \(identifier)" , delegate: nil, cancelButtonTitle: "Thanks for the info!")
alert.show()
return true
}
}
}
return false
}
在iPhone的plist文件中进行以下更改
但我无法使用上述代码打开我的iPhone应用程序。在许多SO链接的某处,我发现了这种方法openParentApplication:
。但是现在也没有这种方法。
任何人,请建议任何有效的解决方案。