O'Reilly logo

Building Cross-Platform Apps using Titanium, Alloy, and Appcelerator Cloud Services by Aaron Saunders

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 10

Sharing via Facebook, Email, and Twitter

APPCELERATOR TITANIUM PROVIDES excellent support for sharing using the Facebook module and also for sharing via email if it is properly configured on the device. There are more options for sharing, specifically Twitter, but that is not currently incorporated into the framework although there are various open source solutions to support that functionality.

In this chapter, you will integrate sharing to the Facebook wall, sharing the photo to the user’s Facebook photo album, sharing the photo on Twitter, and finally sharing the photo as an attachment through email.

The examples here use the Facebook module and custom code from Appcelerator Alloy social.js module for Twitter integration. There are open source modules to integrate social media using the native APIs and the IOS 6 native integration of Facebook and Twitter that can be found in the Appcelerator Marketplace and on Github.

Creating the CommonJS Library for Sharing Functions

To get started, you need to create a new file called sharing.js and add it to the lib folder created previously. In the sharing.js library file you will start off by ensuring that the Facebook module has been loaded. Add the following code to the top of the sharing.js library file:

// if facebook not loaded, then load itif (!Alloy.Globals.FB) {  Alloy.Globals.FB = require('facebook');}// Enabling single sign on using FBAlloy.Globals.FB.forceDialogAuth = false;// get the app idAlloy.Globals.FB.appid ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required