Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 8.3 Share Extension - Launching URL Schemes

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

like image 325
edulpn Avatar asked Apr 15 '15 18:04

edulpn


2 Answers

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:@""]];
        }
    }
like image 137
AdamWang Avatar answered Sep 28 '22 08:09

AdamWang


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.

like image 26
Léo Natan Avatar answered Sep 28 '22 10:09

Léo Natan