rubenfonseca / titanium-social

iOS6 Social module for Titanium
MIT License
11 stars 10 forks source link

social Module

Description

Tap into the new iOS6 Social.framework

Installation

[http://wiki.appcelerator.org/display/tis/Using+Titanium+Modules]()

To use this module since version 1.0 you must be using at least Xcode 4.5 with iOS SDK 6.0 or later.

Changelog

See here

Accessing the social Module

To access this module from JavaScript, you would do the following:

var Social = require("com.0x82.social");

The Social variable is a reference to the Module object.

iOS6 module only

This is an iOS6 module only! If you try to require it on an iOS < = 5 device, it will throw an exception. So you should include some sort of code on your application to check in which version of iOS are you running, and then decide to use or not use this module

function isiOS6Plus()
{
  // add iphone specific tests
  if (Titanium.Platform.name == 'iPhone OS')
  {
    var version = Titanium.Platform.version.split(".");
    var major = parseInt(version[0],10);

    if (major >= 6)
    {
      return true;
    }
  }
  return false;
}  

Reference

Please visit the following links to see the different classes of the application:

Methods

- Social.showActivityItems({...})

This method allows you to access the iOS6+ UIActivityViewController. The UIActivityViewController class is a standard view controller that you can use to offer various services from your application. The system provides several standard services, such as copying items to the pasteboard, posting content to social media sites, sending items via email or SMS, and more.

On the iPad you can optionaly show the controller in a popover. Otherwise, it is presented modally.

The method takes the following arguments:

The following options are only valid on the iPad:

Example:

Social.showActivityItems({
  activityItems: ["This is a text to share"],
  excludedActivityTypes: [Social.UIActivityTypePostToWeibo]
});

This method fires the following two events:

Example:

Social.addEventListener('activityWindowClosed', function(e) {
  alert("activity was completed? " + e.completed);
});

Events

update

The 'update' event is fired on the Social module eveytime something changes about a social network authentication. The event is sent with the following param:

Example usage:

Social.addEventListener('update', function(e) {
  if(e.twitter) { Ti.API.warn("Can post to Twitter"); }
  if(e.facebook) { Ti.API.warn("Can post to Facebook"); }
  if(e.sinaweibo) { Ti.API.warn("Can post to Sinaweibo"); }
});

Constants

Social.DONE

Social.CANCELLED

Used when the ComposerView finished sending a tweet.

Social.REQUEST_METHOD_GET

Social.REQUEST_METHOD_POST

Social.REQUEST_METHOD_DELETE

Used on Request to specify the type of request to be made to the social network

Social.TWITTER

Social.FACEBOOK

Social.SINAWEIBO

Used everytime we need to specify which social networking we are working, except when we dealing with account objects (account store, account credentials, account). For that, use the constants bellow.

Social.ACCOUNT_TWITTER

Social.ACCOUNT_FACEBOOK

Social.ACCOUNT_SINAWEIBO

Used everytime we need to speicify which social networking we are working when dealing with account objects (account store, account credentials, account).

Social.FACEBOOK_APP_ID

Social.FACEBOOK_PERMISSIONS

Social.FACEBOOK_AUDIENCE

Used to specify Facebook options when creating or accessing the Facebook account store. The last key FACEBOOK_AUDIENCE accepts one of the following:

Social.RENEW_RESULT_RENEWED

Social.RENEW_RESULT_REJECTED

Social.RENEW_RESULT_FAILED

Used when renewing account credentials on the AccountStore

Usage

Please see the example directory, since it contains several examples of all the API.

Author

Rúben Fonseca, (C) 2012