iOS 8.3 Share Extension - Launching URL Schemes
Asked Answered
K

2

5

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

Korikorie answered 15/4, 2015 at 18:20 Comment(0)
E
2

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.

Exculpate answered 15/4, 2015 at 18:27 Comment(6)
they seem to have defined this design earlier, I read somewhere Apple don't intend to have extensions working as app launchers, but, as you mentioned, some workarounds were still working until 8.3 came up. weird thing is that there is almost nothing out there about this kind of issue, specially share extensions.Korikorie
I'll wait a bit before accepting your answer, so I might get a more "positive" answer...Korikorie
It can probably still be achieved using "funny" code. You can't call UIApplication.openURL at compile time, but you can probably do it using runtime, and it might work. But that's playing with fire.Dinnerware
@Korikorie This answer is correct, whether it's as "positive" as you like or not.Stowers
I'm not saying I'm not going to accept the answer @TomHarrington... I'm just not too sure that it is correct as you mentioned, because it's not based on some Apple's document, as far as I know... can I accept more than one answer, if another more detailed and supported one should appear? That's what I mean...Korikorie
You can change accepted answer. I will also update my answer if something new comes up.Dinnerware
I
3

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:@""]];
        }
    }
Inconveniency answered 22/4, 2015 at 9:59 Comment(0)
E
2

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.

Exculpate answered 15/4, 2015 at 18:27 Comment(6)
they seem to have defined this design earlier, I read somewhere Apple don't intend to have extensions working as app launchers, but, as you mentioned, some workarounds were still working until 8.3 came up. weird thing is that there is almost nothing out there about this kind of issue, specially share extensions.Korikorie
I'll wait a bit before accepting your answer, so I might get a more "positive" answer...Korikorie
It can probably still be achieved using "funny" code. You can't call UIApplication.openURL at compile time, but you can probably do it using runtime, and it might work. But that's playing with fire.Dinnerware
@Korikorie This answer is correct, whether it's as "positive" as you like or not.Stowers
I'm not saying I'm not going to accept the answer @TomHarrington... I'm just not too sure that it is correct as you mentioned, because it's not based on some Apple's document, as far as I know... can I accept more than one answer, if another more detailed and supported one should appear? That's what I mean...Korikorie
You can change accepted answer. I will also update my answer if something new comes up.Dinnerware

© 2022 - 2024 — McMap. All rights reserved.