从观看应用启动主机应用 [英] Launch host app from watch app
本文介绍了从观看应用启动主机应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道监视工具包扩展中的 openParentApplication
api可以在后台打开主机应用程序,但不能在前台打开。
I know that the openParentApplication
api in watch kit extension can open the host app in the background but not in the foreground.
我还尝试使用 openUrl()
api of NSExtensionContext
,如下所示:
I also tried using openUrl()
api of NSExtensionContext
as below:
NSExtensionContext *ctx = [[NSExtensionContext alloc] init];
NSURL *url = [NSURL URLWithString:@"myScheme://today"];
[ctx openURL:url completionHandler:^(BOOL success) {
NSLog(@"fun=%s after completion. success=%d", __func__, success);
}];
[ctx completeRequestReturningItems:ctx.inputItems completionHandler:nil];
此处主机应用程序也未启动。我错过了什么吗?或者是不可能
从手表套件扩展中启动主机应用程序?
Here too the host app is not launched. Am I missing something? or is it not possible to launch the host app from watch kit extension?
推荐答案
如果您需要要在前台打开您的父应用,请使用Handoff!
https://developer.apple.com/handoff/
https://developer.apple.com/handoff/
示例:
两者共享:
static let sharedUserActivityType = "com.yourcompany.yourapp.youraction"
static let sharedIdentifierKey = "identifier"
在您的手表上:
updateUserActivity(sharedUserActivityType, userInfo: [sharedIdentifierKey : 123456], webpageURL: nil)
您的iPhone上的App代表:
on your iPhone in App Delegate:
func application(application: UIApplication, willContinueUserActivityWithType userActivityType: String) -> Bool {
if (userActivityType == sharedUserActivityType) {
return true
}
return false
}
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
}
最后(这一步很重要!!!):在你的Info.plist中
这篇关于从观看应用启动主机应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文