Created
April 9, 2013 20:35
-
-
Save skypanther/5349155 to your computer and use it in GitHub Desktop.
URLSchemes handling code for TCE lab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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