5

I'm trying to launch the container app from the extension. (An Action extension) The container app has a working URL scheme (example://) and I can validate this by navigating to that URL in Safari.

When I try to use the -[NSExtensionContext openURL:completionHandler:] to launch the container app, I get an unsuccessful callback and nothing happens.

The iOS 8 Beta 2 changes say that the openURL method should work now, but is this still a bug or am I doing something wrong?

Andrew
  • 15,357
  • 6
  • 66
  • 101
Mert Dümenci
  • 493
  • 1
  • 5
  • 18

4 Answers4

10

It worked for me in a Today Extension using this code:

NSExtensionContext *myExtension=[self extensionContext];
[myExtension openURL:[NSURL URLWithString:@"http://google.com"] completionHandler:nil];

However, it might not work in Action Extensions. From the documentation:

Each extension point determines whether to support this method, or under which conditions to support this method. In iOS 8.0, only the Today extension point supports this method.

BFar
  • 2,447
  • 22
  • 23
jk9357
  • 131
  • 4
3

My solution is creating a UIWebView and loading a request with the url in it

nurnachman
  • 4,468
  • 2
  • 37
  • 40
0

If you use unicode character you must convert to utf8 string.

NSString* toUtf8= [yourString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSString *urlString = [NSString stringWithFormat:@"openMap://?lat=%f&lon=%f&%@",[self.koordX floatValue],[self.koordY floatValue],toUtf8];

[self.extensionContext openURL:[NSURL URLWithString:urlString]  completionHandler:nil];
erdikanik
  • 674
  • 9
  • 11
0

https://developer.apple.com/library/prerelease/ios/documentation/Foundation/Reference/NSExtensionContext_Class/index.html#//apple_ref/occ/instm/NSExtensionContext/openURL:completionHandler:

IMPORTANT Apple allows any Today widget to use the openURL:completionHandler: method to open the widget’s own containing app.

If you employ this method to open other apps from your Today widget, your App Store submission might entail additional review to ensure compliance with the intent of Today widgets.

To learn more, read App Store Review Guidelines and iOS Human Interface Guidelines, linked to from Apple’s App Review Support page

HuyLe
  • 1,870
  • 1
  • 14
  • 11