Open URL scheme from iOS extension

◇◆丶佛笑我妖孽 提交于 2019-12-06 16:12:11

问题


I have this code that return success = NO

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

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

 }];

So and I can't open containing app from my share extension when I debug it.

I've configured main target of contained app like this:

I've tested open URLApp:// from safari and it works for me.

I also used some examples provided here to understand how to open containing app using url scheme.


回答1:


EDIT: Ok, just a little correction here. I got it working with placing a button over the label just like suggested above and the following code:

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

I linked it to a "Touch Up Inside" event. However, this also causes the app to launch when the user scrolls the Today view.

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

I ran into the same issue. However, it seems that there is no solution for now since the release notes for the first beta of iOS 8 mention:

Known Issues: openURL does not work from an extension.

So I guess we will at least have to wait until beta 2.




回答2:


I found this answer here by Julio Bailon:

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];


来源:https://stackoverflow.com/questions/29657515/open-url-scheme-from-ios-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!