Skip to content

Instantly share code, notes, and snippets.

@jeffatstepup
Created February 17, 2015 10:18
Show Gist options
  • Save jeffatstepup/3263ee4f7330eeb30399 to your computer and use it in GitHub Desktop.
Save jeffatstepup/3263ee4f7330eeb30399 to your computer and use it in GitHub Desktop.
How to open pkpass files in PassWallet from Appcelerator Titanium
/**
*
* Save pkpass to PassWallet
* See http://passwallet.attidomobile.com/PassWallet%20Developer%20Guide.pdf
*
*/
function shareToPassWallet () {
var pkpassFile,
intent,
packageName = "com.attidomobile.passwallet";
pkpassFile = getPkpass();
if (_.isNull(pkpassFile) || !Ti.Filesystem.isExternalStoragePresent()){
return;
}
pkpassFile.copy(Ti.Filesystem.externalStorageDirectory + Ti.Filesystem.separator + "mbp.pkpass");
pkpassFile = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory + Ti.Filesystem.separator + "mbp.pkpass");
if (!pkpassFile.exists()){
return;
}
intent = Ti.Android.createIntent({
        action: Ti.Android.ACTION_VIEW,
packageName : packageName,
className : "com.attidomobile.passwallet.activity.TicketDetailActivity",
        type: "application/vnd.apple.pkpass",
flags : Ti.Android.FLAG_ACTIVITY_NEW_TASK,
data : pkpassFile.getNativePath()
    });
 
try {
//Open in PassWallet if installed
intent.addCategory(Ti.Android.CATEGORY_BROWSABLE);
    Ti.Android.currentActivity.startActivity(intent);
} catch (ex1) {
try {
//Open Play store app if installed to get PassWallet
intent = Ti.Android.createIntent({
action : Ti.Android.ACTION_VIEW,
data : "market://details?id=" + packageName
});
Ti.Android.currentActivity.startActivity(intent);
} catch (ex2) {
//Open Play store webpage to get PassWallet
intent = Ti.Android.createIntent({
action : Ti.Android.ACTION_VIEW,
data : "http://play.google.com/store/apps/details?id=" + packageName
});
Ti.Android.currentActivity.startActivity(intent);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment