Home

Awesome

TiSocial.Framework Module

Description

The TiSocial.Framework Module extends the Appcelerator Titanium Mobile framework with the iOS6 social.framework. This enables sharing content to Facebook, Twitter and other platforms.

The module is licensed under the MIT license.

SLComposeViewController UIActivityViewController

Referencing the module in your Titanium Mobile application

Simply add the following lines to your tiapp.xml file:

<modules>
    <module platform="iphone">dk.napp.social</module> 
</modules>

Reference

For more detailed code examples take a look into the example app

Twitter

Social.isTwitterSupported()

Returns true or false.
false if no account has been defined (true in the 6.0 simulator) or the iOS Version doesn't support the Social Framework.

Social.twitter({Object} options)

options can have the following keys:

Each of these options is optional

Social.twitterRequest({Object} options [, {Object} requestParameter])

optionshas the following keys:

requestParameter is optional, but is build like this:

{
    'screen_name': 'CBeloch'
}

So screen_name is the parameter name / key and CBeloch is the value of the parameter

Social.twitterAccountList()

Returns a list of twiiter accounts. use the EventListener accountList to capture this list.

Social.addEventListener("accountList", function(e){
    Ti.API.info("Accounts:");
    accounts = e.accounts; //accounts
    Ti.API.info(accounts);
});
Social.twitterAccountList();

Facebook

Social.isFacebookSupported()

Returns true or false.
false if no account has been defined (true in the 6.0 simulator) or the iOS Version doesn't support the Social Framework.

Social.facebook({Object} options)

options can have the following keys:

Each of these options is optional

Social.facebookRequest({Object} options [, {Object} requestParameter])

options has the following keys:

requestParameter is optional, but is build like this:

{
    fields: 'id,name,devices'
}

So fields is the parameter name / key and id,name,devices is the value of the parameter

Social.grantFacebookPermissions

Before you can send request to the Facebook API, you start by getting the users permissions.

var fbAccount;
Social.grantFacebookPermissions({
    appIdKey:"YOUR_FB_APP_ID",
    permissionsKey: "email" //FB docs: https://developers.facebook.com/docs/reference/login/extended-permissions/
});
Social.addEventListener("facebookAccount", function(e){ 
    fbAccount = e.account; //now you have stored the FB account. You can then request facebook using the below method 
});

Social.requestFacebookWithIdentifier({Object} options [, {Object} requestParameter])

Request Facebook with a specific account.

Social.requestFacebookWithIdentifier({
    requestType:"GET",
    accountWithIdentifier: fbAccount["identifier"], //start by granting facebook permissions 
    url:"https://graph.facebook.com/me",
    callbackEvent: "facebookProfile",
}, {
    fields: 'id,name,location'
});

Social.renewFacebookAccessToken

The accessToken will eventually be invalid, if you store the FB acccount in a App property or storage of some kind. This method can renew the accessToken, and make you able to request Facebook again. This method rely on the same facebookAccount eventlistener, as grantFacebookPermissions.

Social.renewFacebookAccessToken();

Sina Weibo

Social.isSinaWeiboSupported()

Returns true or false.
false if no account has been defined (true in the 6.0 simulator) or the iOS Version doesn't support the Social Framework.

Social.sinaweibo({Object} options)

options can have the following keys:

Each of these options is optional

UIActivityViewController

Constants

Events

Social.activityView()

The first required options argument can have the following keys:

The second optional argument is an array with objects. Use this to create custom UIActivities. The posibilties are almost endless. have a look at: http://uiactivities.com for inspiration.

Social.activityView({
    text:"share like a king!",
    subject:"I would like to share this with you",
    image:"pin.png",
    removeIcons:"print,sms,copy,contact,camera,mail",
    emailIsHTML : false
},[
    {
        title:"Custom Share",
        type:"hello.world",
        image:"pin.png",
        callback: function(e) {
            alert("You chose me!");
        }
    },
    {
        title:"Open in Safari",
        type:"open.safari",
        image:"safari.png"
    }
]);

Social.activityPopover() (iPad only)

The first required options argument can have the following keys:

The second optional argument is an array with objects. Use this to create custom UIActivities.

See Social.activityView().

Example of usage

FollowMe Button

example/follow_on_twitter.js contains an example on how to implement a "Follow Me" button. It takes an account the os version and for iOS 5 will try to open the profile page in another application that exits on the device.

Please check the Example section in the file.

Changelog

v.1.8.2

v.1.8.1

v.1.8.0

v.1.7.10

v.1.7.9

v1.7.8

v1.7.7

v1.7.6

v1.7.5

v1.7.4

v1.7.3

v1.7.2

v1.7.1

v1.7.0

v1.6.2

v1.6.1

v1.6.0

v1.5.5

v1.5.4

v1.5.3

v1.5.2

v1.5.1

v1.5

v1.4

v1.3

v1.2

v1.1

v1.0

Author

Mads Møller
web: http://www.napp.dk
email: mm@napp.dk
twitter: @nappdev

Contributors

Christopher Beloch
twitter: @CBeloch

Jongeun Lee
twitter: @yomybaby

Daniel Tamas
twitter: @dan_tamas

Rafael Kellermann Streit
twitter: @rafaelks

Joseandro Luiz
twitter: @joseandroluiz

Carlos Zinato
twitter: @chmiiller

João Paulo
twitter: @juaumlol

License

Copyright (c) 2010-2013 Mads Møller

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.