How to Open a Native iOS App from a Web App

how do I open a native app from a webpage

Ok. So you can use URL schemes.

Here is a list of many apps. But it all comes down to the individual app, if they provide a URL scheme.

For me, I could do like this

<a class="btn btn-outline-primary" href="pic2shop://scan?callback=https3A%2F%2FMyUrl">Scan</a>

This enables me to start a barcode scanner app, scan a barcode, and get a callback with the extracted number.

Open iOS app from browser

You can achieve what you're asking for by using a URL scheme. This will enable you to call the openUrl: method with your application's url scheme which will then launch your app.
Here's how you setup a custom url scheme:

  1. Open your app's Info.plist and add a row with a key called URL Types.
  2. Expand the URL Types item, and Item 0 under it and you'll see URL Identifier
  3. Enter your app's bundle identifier (e.g. com.myCompany.myApp) as the URL Identifier value.
  4. Add another row to Item 0 and enter URL Schemes.
  5. Expand the URL Schemes and under Item 0 type in the name for your custom scheme (e.g. myScheme).

You should now be able to open your app from Safari by typing myScheme:// in the address bar.
Alternatively, from your app, you can launch the other app like this:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"myScheme://"]];

Note that you can also send parameters to the app you're launching with the url scheme (more on that here).

Open external link from web app packaged as native iOS app

I haven't discovered a way to do this with sencha native packaging.

But wrapping the application in a phonegap and compiling the application in Xcode, with required urls added to the ExternalHost array in phonegap.plist should work right?

Also, (still on the Phonegap solution) I assume hacking AppDelegate.m to open links in Safari would work just as fine.

Is it possible to open an Native iOS app by using Custom url scheme without a webpage directs to custom url?

The simple answer is likely no, as you have little control over how individual apps will handle links. The complex answer is that you should do something about it. Note that it won't always require returning a full web page -- on Android with Chrome you can fire a 307 redirect straight to a Chrome intent.

You could set up a simple web server that, when pinged, returns `window.location = 'test://'.

Or better yet, you can try to open the URI scheme in an iframe then fallback to a web URL if the app isn't present. This can be achieved using the following mechanisms:

  1. on iOS 9, use Universal Links
  2. in Chrome (and soon, Firefox 41.0!) use Chrome Intents
  3. on all other browsers, use client-side javascript

Here's an example of client-side javascript:

<script type="text/javascript">
window.onload = function() {
// Deep link to your app goes here
document.getElementById("l").src = "my_app://";

setTimeout(function() {
// Link to the App Store should go here -- only fires if deep link fails
window.location = "https://itunes.apple.com/us/app/my.app/id123456789?ls=1&mt=8";
}, 500);
};
</script>
<iframe id="l" width="1" height="1" style="visibility:hidden"></iframe>

This is exactly what we do at my company, branch.io. We're constantly dealing with changes to browsers and webviews because there are always new scenarios to cover. It's essential to look at the user agent string when deciding how to deeplink a user into your app.

iOS web app as native app

If i am not wrong the only thing u need to perform is to get web view refreshed when an edit is perform on remote .txt file. in my view You can download the file whenever your app is run for the first time and later on set timer that will check remote file attributes in an interval(say 1min or one sec).
Here is sample code that will trigger and return true if file is modified.

//here is sample code that will return true if file is modified
//url:your remote file url. filePathe: local file that you downloade when you app is run for first time
+ (BOOL)isServerURL:(NSString *)url NewerThanLocalFile:(NSString *)filePath {

if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {


NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];

NSDate *date = [attributes fileModificationDate];

NSString *lastModifiedString = nil;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString: url] cachePolicy:NSURLCacheStorageAllowed timeoutInterval:2];
[request setHTTPMethod:@"HEAD"];
NSHTTPURLResponse *response;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error: NULL];
if ([response respondsToSelector:@selector(allHeaderFields)]) {
lastModifiedString = [[response allHeaderFields] objectForKey:@"Last-Modified"];
}

NSDate *lastModifiedServer = nil;
@try {

//set time format as required
NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.dateFormat = @"EEE',' dd MMM yyyy HH':'mm':'ss 'GMT'";
df.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
df.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
lastModifiedServer = [df dateFromString:lastModifiedString];
}
@catch (NSException * e) {
NSLog(@"Error parsing last modified date: %@ - %@", lastModifiedString, [e description]);
}

if ([date laterDate:lastModifiedServer] == lastModifiedServer)
{
return YES;
} else {
return NO;
}

} else {
return YES;
}
}

If timer returns YES refresh your web-view.Hope i am clear.

How to recommend a native app when viewing web app in devices?

On iOS, you're thinking of Smart App Banners, which are a website configuration detail to display a banner for the user to view your iOS app in the App Store:

Sample Image

iOS app, link to open website in browser, link in website closes browser

Launching Your Own Application via a Custom URL Scheme and Pass Parameters.

Here is a nice tutorial on Using Custom URL Scheme in iOS

As in the tutorial, you should parse the URL parameters and store them to use in the app in this method:

    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
NSLog(@"Calling Application Bundle ID: %@", sourceApplication);
NSLog(@"URL scheme:%@", [url scheme]);
NSLog(@"URL query: %@", [url query]);

return YES;
}

Opening Native App. from Safari

Yes, you can do this by binding your application to a custom URI scheme and then creating a link with your custom URI scheme which, when selected, will open your app.

To register the custom URI scheme you'll need to modify the info.plist file and assign your custom value to the URL Identifier object.

You can review the iPhone OS Programming Guide Apple developer documentation for further details or this article which details the step-by-step process in-depth.

Or you can check out the official documentation from Apple.



Related Topics



Leave a reply



Submit