Mert Dümenci
Mert Dümenci

Reputation: 513

NSExtensionContext openURL doesn't work

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?

Upvotes: 7

Views: 7117

Answers (4)

HuyLe
HuyLe

Reputation: 1900

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

Upvotes: 0

erdikanik
erdikanik

Reputation: 744

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];

Upvotes: 0

jk9357
jk9357

Reputation: 141

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.

Upvotes: 11

nurnachman
nurnachman

Reputation: 4565

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

Upvotes: 4

Related Questions