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.
Asked
Active
Viewed 452 times
1
-
possible duplicate of [launch safari from iphone app](http://stackoverflow.com/questions/822599/launch-safari-from-iphone-app) – n00bProgrammer Sep 21 '14 at 07:56
-
custom keyboard does not use its own application context but uses extension context, so I think not duplicate. Please reverify. – bllakjakk Sep 21 '14 at 08:04
-
@ n00bProgrammer I want to launch browser from iOS 8 extension not from iPhone Application. – Sukhpal Singh Sep 21 '14 at 09:03
-
Anyone got the solution ? – Jaha Rabari Nov 29 '14 at 18:13
1 Answers
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
-
-
-
custom uri scheme can also be used to handle other apps. Also simulator behaviour is well-defined for this scenario. – bllakjakk Sep 21 '14 at 09:12
-
I tried like this : NSURL *url = [NSURL URLWithString:@"http://maps.apple.com/?daddr=San+Francisco,+CA&saddr=cupertino"]; [webView loadRequest:[NSURLRequest requestWithURL:url]]; but it is not working. It is open link in webview. But if I open above link in Safari browser it opens Maps App. – Sukhpal Singh Sep 21 '14 at 09:29
-
-
1i had tried above solution but in Keyboard it is not working. Please help if anyone got the solution. – Jaha Rabari Nov 29 '14 at 18:19