1

Can I launch browser using custom keyboard in iOS8. I created custom keyboard and added an icon of browser. Now i want to launch browser when user tap on it.

Sukhpal Singh
  • 672
  • 1
  • 12
  • 31

1 Answers1

1

You can use below api from NSExtensionContext class. Btw. the NSExtensionContext object represents the host app context from which an app extension is invoked.

- (void)openURL:(NSURL *)URL
completionHandler:(void (^)(BOOL success))completionHandler

Below is a sample:

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

But there is a catch. Each extension point determines whether to support this method, or under which conditions to support this method.

So in that case you should use a WebView and load the request within it to redirect to the browser.

Edit1:

To redirect to safari from Webview try this:

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
        //[[UIApplication sharedApplication] openURL:[inRequest URL]];
          [myExtension openURL:url completionHandler:nil];
          return NO;

}

Also If you need to directly launch native app use predefined schemes like:

maps://

bllakjakk
  • 5,045
  • 1
  • 18
  • 28