Gan*_*yak 12 iphone ios apple-watch watchkit
我知道openParentApplication
手表套件扩展中的api可以在后台打开主机应用程序,但不能在前台打开.
我也尝试过如下的openUrl()
api NSExtensionContext
:
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];
Run Code Online (Sandbox Code Playgroud)
这里也没有启动主机应用程序.我错过了什么吗?或者是否无法从手表套件扩展程序启动主机应用程序?
lvp*_*lvp 21
从iOS 8.2的Beta 3开始,目前无法将iOS应用程序打开到前台.如你所说openParentApplication
可以在后台打开应用程序.不幸的是,在iPhone上没有API打开应用程序的迹象.
Apple Dev论坛上的多篇帖子提到它是不可能的
https://devforums.apple.com/message/1076125#1076125
正确的是,通知仍然可以声明iPhone应用程序将处理的后台操作,因此从这个意义上说它可以启动iPhone应用程序.但是,通过WatchKit应用程序无法将iPhone应用程序带到前台.
等帖子
https://devforums.apple.com/message/1082620#1082620
在设备上,[Watch app]不会 - 将您的iOS应用程序带到前台.
小智 12
我希望Apple能够提供API,以便在未来的测试版中从手表应用程序启动父应用程序,但是现在我已经通过以下方式实现了它...
openParentApplication:reply:
正常呼叫:
- (void)openPhoneApp {
[WKInterfaceController openParentApplication:[NSDictionary new] reply:nil];
}
Run Code Online (Sandbox Code Playgroud)
application:handleWatchKitExtensionRequest:reply:
在AppDelegate中实现,并使用自定义URL方案启动自身:
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"myappscheme://open"]];
}
Run Code Online (Sandbox Code Playgroud)
如果您需要在前台打开您的父应用程序,请使用Handoff!
https://developer.apple.com/handoff/
示例:
某处共享两者:
static let sharedUserActivityType = "com.yourcompany.yourapp.youraction"
static let sharedIdentifierKey = "identifier"
Run Code Online (Sandbox Code Playgroud)
在你的手表上:
updateUserActivity(sharedUserActivityType, userInfo: [sharedIdentifierKey : 123456], webpageURL: nil)
Run Code Online (Sandbox Code Playgroud)
在你的iPhone App Appate:
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
}
Run Code Online (Sandbox Code Playgroud)
最后(这一步很重要!):在你的Info.plist(s)中
归档时间: |
|
查看次数: |
7775 次 |
最近记录: |