views:

193

answers:

2

Hello guys,

I'm creating a website for iPhone and i use the native app (cliqcliq Quickpick) to upload photos. I use the script like the following to check if the application is installed. The basic idea is to send user to a custom url, if application is there it is launched, if it is not there the url should be ignored and user is taken to App Store. Below is the script:

window.launchQuickpic = function() {
    var start = new Date();
 setTimeout(function() {
     if (new Date() - start > 2000) {
     return;
    }
    window.location = 'http://www.cliqcliq.com/quickpic/install/';
}, 1000);

    var getParams = [...];
    window.location = 'vquickpic://?' + getParams.join('&');
};

If the native app is not installed I'm getting the alert box saying that Safari does not recognize the custom url. After user clicks "ok" it works as it is supposed to. But the alert is reeealy annoying.

I've tried to surround the window.location= code with try/catch. Didn't help.

A: 

If I understand correctly, you're seeing the expected behavior.

If the app isn't installed then the system has no knowledge of what it is supposed to do with a URL that starts with 'vquickpic://'. That is why you get the error message.

I presume that what you are seeing is that you first set the window.location to 'http://www.cliqcliq.com/quickpic/install/' but before that finishes loading you try to switch to window.location to 'vquickpic://'. That generates an error and the webview keeps loading the first URL when you dismiss the alert.

The main problem here is that the error is coming from the iPhone OS itself which isn't accessible from the javascript inside a webpage. A webpage can't ask the iPhone if it has a particular app installed or can carry out a particular operation.

I think the best you can do is tell the user that clicking the link will attempt to launch the native app if it is installed but if they get an error they need to dismiss it and hit another link on the page to install the app.

TechZen
Well, since the alert is coming from browser, it will be pretty natural to give some way to handle it like the exception, but unfortunately it doesn't work like this.
Juriy
The alert isn't coming from the browser it comes from the OS. The URL handling system is universal. Browsers are just one type of app that uses them. You can put links that open custom URL protocols in any application. The system sets Safari to handle common web related protocols but you can change that. Other applications handle other protocols. The system has no safe way to route the result of any random protocol request back the javascript in any random web browser.
TechZen
A: 

OR maybe you could try Opera Mini for that matter

Markos
Unfortunately I can't demand to use specific browser from my users. So that way will not cover every user.
Juriy