|
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(); |
|
} |