Skip to content

Instantly share code, notes, and snippets.

@adampax
Last active May 24, 2022 17:02
Show Gist options
  • Save adampax/0fc795dae2d0c4ec6cda to your computer and use it in GitHub Desktop.
Save adampax/0fc795dae2d0c4ec6cda to your computer and use it in GitHub Desktop.
Appcelerator Titanium Social Sharing with TiSocial and Intents
//must have TiSocial module installed for iOS: https://github.com/viezel/TiSocial.Framework
//share() Android -- uses intent, iOS --- uses TiSocial share dialog
//tweet iOS Only -- uses TiSocial tweet dialog
function onClickShare(){
require('socialmod').share({
text: 'text to share',
title: 'Title',
url: 'http://example.com'
});
}
function onClickTweet(){
//iOS only.
require('socialmod').tweet({
text:'tweet message',
image:'image.png',
url: 'http://example.com'
});
}
var share, tweet;
var args;
const ITUNES_LINK = 'http://itunes.apple.com/us/app/....';
const GOOGLE_LINK = 'http://play.google.com/store/apps/details?id=com.yourapp';
if (Ti.Platform.osname === 'android') {
share = tweet = function(args) {
var intent = Ti.Android.createIntent({
t action : Ti.Android.ACTION_SEND,
type : "text/plain"
});
intent.putExtra(Ti.Android.EXTRA_TEXT, args.text);
intent.addCategory(Ti.Android.CATEGORY_DEFAULT);
try {
Ti.Android.currentActivity.startActivity(intent);
} catch (ex) {
Ti.UI.createAlertDialog({
title: ' ',
message : 'Complete action using -- Hey, install some sharing apps!'
}).show();
}
};
} else {
var Social = require('dk.napp.social');
var fbAccount;
Social.addEventListener("facebookAccount", function(e){
Ti.API.info("facebookAccount: "+e.success);
fbAccount = e.account;
openActivityView();
});
share = function(textObj) {
args = textObj || {};
if (Social.isActivityViewSupported()) {//min iOS6 required
if(Ti.Platform.model !== 'Simulator'){
getFacebookPermissions();
} else {
openActivityView();
}
} else {
openEmailDialog(args);
}
};
tweet = function(args) {
args = args || {};
if (Social.isTwitterSupported()) {//min iOS5 required
//text image url
Social.twitter(args);
} else {
alert('Please Install a Twitter client');
}
};
}
exports.share = share;
exports.tweet = tweet;
function getFacebookPermissions(){
if(Social.isFacebookSupported()){ //min iOS6 required
Social.grantFacebookPermissions({
appIdKey:"11111111111",
permissionsKey: "email", //FB docs: https://developers.facebook.com/docs/reference/login/extended-permissions/
});
} else {
Ti.API.info('facebook not supported');
openActivityView();
}
}
function openActivityView(){
Social.activityView({
text : args.text,
removeIcons : "print,copy,contact,camera,weibo"
});
}
function openEmailDialog(args){
Ti.UI.createEmailDialog({
subject : args.title,
messageBody : args.title + '</b><br><br>' + args.url + '<br><br>Get thea pp for <a href="' + ITUNES_LINK + '">iPhone</a> and <a href="' + GOOGLE_LINK + '">Android</a>',
html : true
}).open();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment