Created
May 29, 2013 16:57
-
-
Save meeech/5671871 to your computer and use it in GitHub Desktop.
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
/** | |
* RULES: | |
* PAUSE event always seems to remember the last URL value | |
* So, if you launch app with URL, then PAUSE, getArgs will still have URL in it | |
* Same for if you pause app, | |
* resume it with a URL, then pause, same thing - it remains the first time. | |
* Incoming query string values should be encoded according to http://www.faqs.org/rfcs/rfc3986.html | |
* (basically, php rawurlencode) | |
*/ | |
var logger = require('logger') | |
, log = logger.log | |
, qs = require('/lib/querystring') | |
; | |
var win = Ti.UI.createWindow({backgroundColor: '#fff'}); | |
win.open(); | |
win.add(logger.output); | |
var parseLaunchUrl = function() { | |
var data = Ti.App.getArguments() | |
, scheme = 'scratch://' ; | |
log(data); | |
if(data.url) { | |
var urlParts = data.url.replace(scheme, '').split('?'); | |
var parsed_url = { | |
action: urlParts[0] | |
, querystring: qs.parse(urlParts[1]) | |
}; | |
log(parsed_url.action); | |
log(parsed_url.querystring); | |
return parsed_url; | |
} | |
return false; | |
}; | |
Ti.App.addEventListener('resume',function() { | |
log('Resume'); | |
parseLaunchUrl(); | |
}); | |
var start = function() { | |
log('Start App'); | |
parseLaunchUrl(); | |
}; | |
start(); | |
//scratch://new?q=x&v=y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment