Appcelerator Titanium: Learning by examples #4

Titanium modules: Facebook

  1. Module collections: For Facebook we do not need to download anything from market place.
  2. Download a module and save it under /modules dir, inside Titanium SDK folder. Make sure to place module in proper OS (iOS, Android etc)
  3. Add the module in tiapp.xml file. Click on Add button and add Facebook
  4. Add the module in alloy.js file. For example,
    Alloy.Globals.Facebook = require('facebook')
  5. Lets add Login button. Add the code in index.html
    <LoginButton id="fbLoginButton" ns="Alloy.Globals.Facebook"/
  6. Add the code in index.js
  7. var facebook = Alloy.Globals.Facebook;
    facebook.appid = 122761107792145;
    facebook.permissions = ['publish_stream'];
    facebook.addEventListener('login', function(e) {
    	if (e.success) {
    		alert('Logged in!');
  8. For iOS, the following code need to be added manually in tiapp.xml file.
                        <!-- Application ID same as the id value in the tiapp.xml file -->
                            <!-- Prefix the Facebook App ID with 'fb' -->

File System

function saveFile() {
	var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationCacheDirectory, "file.txt");
	/** other options are
	 * Ti.Filesystem.applicationDataDirectory
	 * Ti.Filesystem.applicationDirectory
	 * Ti.Filesystem.applicationSupportDirectory
	if (file.exists) {
	file.write("hello world from file");
	file = null;

function loadFile() {
	var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationCacheDirectory, "file.txt");
	alert("File content: " +;
	file = null;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.