1) Create your own URL scheme in your application. Follow the link if you do not know how to create a custom URL scheme: http://www.idev101.com/code/Objective-C/custom_url_schemes.html
2) Then add the following script to the URLs you want to open.
<script language="javascript" type="text/javascript"> var iOS = (navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false); var appUrlScheme = "myappscheme://" + document.URL; if (iOS) { window.open(appUrlScheme, "_self"); } </script>
The script is self-evident if it is an iOS device, then it just tries to open the current url with your custom URL scheme, i.e. myappscheme://whateverurl.com'. If you app is installed on the device then iOS is going to launch your app and pass this URL to myappscheme://whateverurl.com'. If you app is installed on the device then iOS is going to launch your app and pass this URL to handleOpenURL function, otherwise mobile safari will silently ignore window.open`, and your web page will load as usual:
3) Add the handleOpenURL callback method to AppDelegate to handle the url:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { NSLog(@"url: %@", url); NSLog(@"query string: %@", [url query]); NSLog(@"host: %@", [url host]); NSLog(@"url path: %@", [url path]);
source share