Skip to content

Instantly share code, notes, and snippets.

@skypanther
Created April 9, 2013 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skypanther/5349155 to your computer and use it in GitHub Desktop.
Save skypanther/5349155 to your computer and use it in GitHub Desktop.
URLSchemes handling code for TCE lab
function urlParser(url) {
url = url.replace(/[Uu]rlschemes:\/\/\?/,"");
return url.split('&');
}
// check for arguments passed to this app
if(OS_IOS) {
function grabArguments() {
var args = Ti.App.getArguments();
if(args.url) {
// property present only if app has been launched from the other app
var parsedArgs = urlParser(args.url);
//alert(JSON.stringify(parsedArgs));
switch(parsedArgs[0]) {
case 'maps':
doClickMaps();
break;
case 'youtube':
doClickYouTube();
break;
}
}
}
// grab the arguments when the app is opened from a closed state
grabArguments();
// then, we need to explicitly handle a resumed app state. but
// be careful, we must listen for 'resumed' not 'resume'
// see http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.App-event-resumed
Ti.App.addEventListener('resumed', grabArguments);
} else {
// on Android ...
var activity = Ti.Android.currentActivity;
activity.addEventListener("create", function(e) {
var args = activity.getIntent().getData();
if(args && args != 'urlschemes://') {
var parsedArgs = urlParser(args);
//alert(JSON.stringify(parsedArgs));
switch(parsedArgs[0]) {
case 'maps':
doClickMaps();
break;
case 'youtube':
doClickYouTube();
break;
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment