iOS 8.3 Share Extension - Launching URL Schemes

2020-05-24 06:12发布

since iOS 8.3 update my share extension (which calls my main app using URL Schemes) stopped working. So I found out that the UIWebView approach I had to launch my app is not working anymore. I also tried the approach Apple recommends, using NSExtensionContext, and still no results. Any thoughts about this? My code follows:

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

and

[self.extensionContext openURL:[NSURL URLWithString:urlString] completionHandler:^(BOOL success)
{
    NSLog(@"fun=%s after completion. success=%d", __func__, success);
}];

I try executing both blocks of code on the didSelectPost method from my SLComposeServiceViewController controller, which was where it worked fine previously, before updating my device to iOS 8.3

2条回答
家丑人穷心不美
2楼-- · 2020-05-24 06:44

extensionContext.openURL is meant only for Today extensions. Apple does not provide a public API to achieve this, and it seems in iOS 8.3, Apple has blocked some of the workarounds. This seems by design. If you believe this functionality is needed, please open an enhancement request / bug report.

查看更多
走好不送
3楼-- · 2020-05-24 06:50

You can make a try with this code, this works but I don't know if would be accepted by Apple.

UIResponder* responder = self;
    while ((responder = [responder nextResponder]) != nil) {
        NSLog(@"responder = %@", responder);
        if ([responder respondsToSelector:@selector(openURL:)] == YES) {
            [responder performSelector:@selector(openURL:) withObject:[NSURL URLWithString:@""]];
        }
    }
查看更多
登录 后发表回答