Ccna final exam - java, php, javascript, ios, cshap all in one. This is a collaboratively edited question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
Tuesday, May 1, 2012
iPhone Safari: check if URL scheme is supported in javascript?
Is there any way to check if a URL scheme is currently registered on the phone... with javascript?
Not seamlessly. But there is a way similar to checking if a pop-up was blocked or not.
When you try a URL scheme which is not supported, Safari will warn the user that it doesn't know what to do with it and stay on the same page.
So if you gave your app-call some time to activate, say 300 ms, and then do something else to respond to the non-existence of the scheme.
It's not the prettiest but it works:
function startIThrown(){ document.location = 'ithrown://restart'; setTimeout(function(){ if(confirm('You do not seem to have iThrown installed, do you want to go download it now?')){ document.location = 'http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=293049283&mt=8&uo=6'; } }, 300); }
Here is a solution that does not show the popup when you come back from the app, it assumes you've been gone longer than 400 ms:
function startiThrown() { document.location = appurl; var time = (new Date()).getTime(); setTimeout(function(){ var now = (new Date()).getTime();
if((now-time)<400) { if(confirm('You do not seem to have iThrown installed, do you want to go download it now?')){ document.location = 'http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=293049283&mt=8&uo=6'; } } }, 300); }
No, not from a webpage.
ReplyDeleteNot seamlessly.
ReplyDeleteBut there is a way similar to checking if a pop-up was blocked or not.
When you try a URL scheme which is not supported, Safari will warn the user that it doesn't know what to do with it and stay on the same page.
So if you gave your app-call some time to activate, say 300 ms, and then do something else to respond to the non-existence of the scheme.
It's not the prettiest but it works:
function startIThrown(){
document.location = 'ithrown://restart';
setTimeout(function(){
if(confirm('You do not seem to have iThrown installed, do you want to go download it now?')){
document.location = 'http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=293049283&mt=8&uo=6';
}
}, 300);
}
<a href="#" onclick="startIThrown()">Restart iThrown</a>
Here is a solution that does not show the popup when you come back from the app, it assumes you've been gone longer than 400 ms:
ReplyDeletefunction startiThrown() {
document.location = appurl;
var time = (new Date()).getTime();
setTimeout(function(){
var now = (new Date()).getTime();
if((now-time)<400) {
if(confirm('You do not seem to have iThrown installed, do you want to go download it now?')){
document.location = 'http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=293049283&mt=8&uo=6';
}
}
}, 300);
}