从iOS扩展程序打开URL方案

时间:2015-04-15 18:02:24

标签: ios ios8 ios8-extension ios8-share-extension

我有这个返回success = NO

的代码
[self.extensionContext openURL:[NSURL URLWithString:@"URLApp://"] completionHandler:^(BOOL success) {

     [self.extensionContext completeRequestReturningItems:nil completionHandler:nil];

 }];

因此,我在调试时无法从共享扩展程序中打开包含应用程序。

我已经像这样配置了包含app的主要目标:

enter image description here

我已经在safari中测试了开放URLApp://,它对我有用。

我还使用了here提供的一些示例来了解如何使用url方案打开包含应用程序。

2 个答案:

答案 0 :(得分:0)

编辑:好的,这里稍作修改。我按照上面的建议和以下代码在标签上放置一个按钮就可以了:

 NSURL *url = [NSURL URLWithString:@"floblog://"];
 [self.extensionContext openURL:url completionHandler:nil]; 

我将它与“Touch Up Inside”活动联系起来。但是,这也会导致应用程序在用户滚动“今日”视图时启动。

=======================================

我遇到了同样的问题。但是,似乎现在没有解决方案,因为iOS 8的第一个测试版的release notes提到了:

  

已知问题:openURL无法通过扩展程序运行。

所以我想我们至少要等到beta 2。

答案 1 :(得分:0)

我在Julio Bailon找到了这个答案here

UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
NSString *urlString = @"URLApp://";
NSString * content = [NSString stringWithFormat : @"<head><meta http-equiv='refresh' content='0; URL=%@'></head>", urlString];
[webView loadHTMLString:content baseURL:nil];
[self.view addSubview:webView];
[webView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:2.0];