Skip to content

Instantly share code, notes, and snippets.

@mitulbhalia
Last active January 2, 2016 04:49
Show Gist options
  • Save mitulbhalia/8253514 to your computer and use it in GitHub Desktop.
Save mitulbhalia/8253514 to your computer and use it in GitHub Desktop.
function handle_attachments() {
// make sure we have new args before firing
// prevents handling of the same file every time the app opens, resumes, etc
args = Ti.App.getArguments();
var file = args.url;
var source = args.source;
// make sure we have something to work with
if(!file) {
return false;
}
//opening text file
if( file.indexOf('.txt') != -1 ) {
curr_note_args = Ti.App.Properties.getString('curr_note_args');
if(curr_note_args == args.url) {
return false;
}
// DO SOMETHING HERE
Ti.App.Properties.setString('curr_note_args', args.url);
}
// opening wave file
if( file.indexOf('.wav') != -1 ) {
curr_audio_args = Ti.App.Properties.getString('curr_audio_args');
if(curr_audio_args == args.url) {
return false;
}
// DO SOMETHING HERE
Ti.App.Properties.setString('curr_audio_args', args.url);
}
}
// Ti doesn't have an 'open' listener for the app so we listen on the main window
b.addEventListener('open', function(e) {
handle_attachments();
});
Ti.App.addEventListener('resume', function(e) {
handle_attachments();
});
Ti.App.addEventListener('resumed', function(e) {
handle_attachments();
});
Ti.App.addEventListener('pause', function(e) {
handle_attachments();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment