1

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:

enter image description here

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.

Matrosov Oleksandr
  • 25,505
  • 44
  • 151
  • 277
  • Possibly related Q&A: [openURL from App Extension](http://stackoverflow.com/questions/24356314/openurl-from-app-extension). – jweyrich Apr 15 '15 at 18:05
  • You're using an URL with only a scheme. Have you tried a more valid URL? like `[NSURL URLWithString:@"URLApp://openApp"]` – Marc-Alexandre Bérubé Apr 15 '15 at 18:07
  • @Marc-AlexandreBérubé i've answered my comment, what do you think. it works for me. – Matrosov Oleksandr Apr 15 '15 at 18:20
  • 2
    That method doesn't work because it's designed to not work in share extensions. The docs for the method say **In iOS 8, only the Today extension point (used for creating Today widgets) supports this method.** – Tom Harrington Apr 15 '15 at 18:30

2 Answers2

0

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.

Rahul Mayani
  • 3,761
  • 4
  • 25
  • 40
  • We're past iOS 8.0 Beta 2 for a while now. As of the date of this comment, the latest iOS version is 8.3. But I think the restriction (be it an issue or by design) still remains - haven't tested though. – jweyrich Apr 15 '15 at 18:15
  • @jweyrich i answered my question. what do you think? – Matrosov Oleksandr Apr 15 '15 at 18:19
  • @MatrosovAlexander does it solve your problem? If so, you may accept your own answer. I'd also recommend up-voting the original answer you used as reference. The guy deserves an incentive as well :-) – jweyrich Apr 15 '15 at 18:29
0

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];
Community
  • 1
  • 1
Matrosov Oleksandr
  • 25,505
  • 44
  • 151
  • 277
  • 2
    Does that actually work for you? That answer is a few months old and [a more recent question](http://stackoverflow.com/questions/29657857/ios-8-3-share-extension-launching-url-schemes) suggest that it doesn't work in newer versions of iOS. – Tom Harrington Apr 15 '15 at 19:18
  • @TomHarrington, hm omg, but what can be a solution? it's no so good, so in case if I don't have configured account I can use share extension to send data to server, so I want to say to user - "Open app to sign in". do you have any thoughts how to provide open app feature? – Matrosov Oleksandr Apr 15 '15 at 19:58
  • 1
    You don't. In the question you linked to, the person who wrote the accepted answer is one of the Apple engineers who developed app extensions. Apple doesn't want it to work that way and is closing down any workarounds that people find. File a bug with Apple and hope that they change it. – Tom Harrington Apr 15 '15 at 20:26