Skip to content

Instantly share code, notes, and snippets.

@nuno
Last active January 2, 2016 20:59
Show Gist options
  • Save nuno/8360323 to your computer and use it in GitHub Desktop.
Save nuno/8360323 to your computer and use it in GitHub Desktop.
Ti.SocialShare sample provided by @raulriera
function shareMessage() {
var shareMessageFull = $.message.text;
var shareMessageEmail = shareMessageFull + "\n\nView more at http://spiritualmixapp.com";
var shareMessageTwitter = shareMessageFull.substring(0, 123) + " via @LiveLoveRaw";
if (OS_ANDROID) {
try {
var intTwitter = Ti.Android.createIntent({
action : Ti.Android.ACTION_SEND,
packageName : "com.twitter.android",
className : "com.twitter.android.PostActivity",
flags : Ti.Android.FLAG_ACTIVITY_NEW_TASK,
type : "text/plain"
});
intTwitter.putExtra(Ti.Android.EXTRA_TEXT, shareMessageTwitter);
Ti.Android.currentActivity.startActivity(intTwitter);
} catch(x) {
var intShare = Ti.Android.createIntent({
action : Ti.Android.ACTION_SEND,
type : "text/plain"
});
intShare.putExtra(Ti.Android.EXTRA_TEXT, shareMessageFull);
Ti.Android.currentActivity.startActivity(intShare);
}
} else {
var optionsDialog = Titanium.UI.createOptionDialog({
options : ["Email", "Facebook", "Twitter", "Cancel"],
cancel : 3,
title : "How should we share the love?"
});
optionsDialog.show();
optionsDialog.addEventListener('click', function(e) {
if (e.index == 0) {
var emailDialog = Ti.UI.createEmailDialog()
emailDialog.subject = "Here a token of love";
emailDialog.messageBody = shareMessageEmail;
emailDialog.open();
}
if (e.index === 2) {
var Social = require("dk.napp.social");
if (Social.isTwitterSupported()) {
Social.twitter({
text : shareMessageTwitter
});
} else {
alert(L("Sorry, looks like you don't have twitter enabled"));
}
}
if (e.index === 1) {
var Social = require("dk.napp.social");
if (Social.isFacebookSupported()) {
Social.facebook({
text : shareMessageFull,
url : "http://spiritualmixapp.com"
});
} else {
alert("Sorry, looks like you don't have Facebok enabled");
}
}
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment