Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Mobile Safari's custom URL Scheme? [duplicate]

iOS URL Schemes allow web sites to launch apps like so:

  • twitter://timeline launches Twitter
  • googlechrome://google.com launches Chrome
  • fb://root launches Facebook
  • ______________ launches Safari? (not http://, since Safari won't launch from UIWebView)

What custom url scheme triggers Safari to launch (even from within another app's UIWebView)?

To clarify, I'm not looking for [[UIApplication sharedApplication] openURL: request.URL];

Instead I'm looking for how a website can allow a user to launch Mobile Safari from within the UIWebView of another app (Google Chrome, Twitter, etc.).

Example HTML links that pop open other apps:

<a href="twitter://timeline">Open Twitter</a> <a href="googlechrome://google.com">Open site in Chrome</a> <a href="fb://root">Open Facebook</a> 

I'm looking for something similar to these non-working examples:

<a href="safari://google.com">Open Safari [Doesn't work]</a> <a href="webkit://google.com">Open Webkit [Doesn't work]</a> 

Here's a jsFiddle of the same: http://jsfiddle.net/gXLjF/9/embedded/result/

Try opening this URL in iOS Google Chrome and opening Safari with the links.

like image 450
Ryan Avatar asked Mar 25 '14 17:03

Ryan


People also ask

What is a custom URL scheme?

Custom URL schemes provide a way to reference resources inside your app. Users tapping a custom URL in an email, for example, launch your app in a specified context. Other apps can also trigger your app to launch with specific context data; for example, a photo library app might display a specified image.

What is URL scheme in Android?

In Android 1.0, the Android URI scheme deep linking mechanism was created. It allows the developer to register their app for a URI (uniform resource identifier) in the operating system for a specific device once the app is installed.

What is app URL scheme?

The app: URL scheme can be used by packaged applications to obtain resources that are inside a container. These resources can then be used with web platform features that accept URLs.

What is URL scheme in iOS?

Overview. A URL scheme allows you to launch a native iOS application from another iOS app or a web application. You can set options in the URL that will be passed to the launched application.


1 Answers

There is no Safari URL scheme. If you make one up and use it in your html you can check for it though.

Implement the UIWebViewDelegate method webView:shouldStartLoadWithRequest:navigationType:. Return 'NO' for the requests that you want to shunt to mobile safari. Call UIApplication openURL with the request's URL.

Something like this:

- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {     // all clicked links!     if ( navigationType == UIWebViewNavigationTypeLinkClicked )     {         [[UIApplication sharedApplication] openURL: request.URL];         return NO;     }      // or, custom URL scheme!     if ( [request.URL.scheme isEqualToString: @"my-open-in-safari"] )     {         // remap back to http.  untested!         NSURL* url = [NSURL URLWithString: [request.URL.absoluteString stringByReplacingOccurrencesOfString: @"my-open-in-safari" withString: @"http" ]];          [[UIApplication sharedApplication] openURL: url];         return NO;     }      return YES; } 
like image 107
TomSwift Avatar answered Oct 11 '22 10:10

TomSwift