Titanium ACS API in PhoneGap

Appcelerator Titanium is Cross platform application development framework. Currently Appcelerator providing free cloud service for Now. There are two plans Tier 1 and Tier 2. Both are currently having limitations. But good for starting new applications. No need to write server side code, like basic things create users, like, chat and so on there by default. And Titanium Mobile SDK 2.0+ having cloud module. Using that we can create users, events, check-ins and so on. This ACS service is not only for Titanium, they’re providing Rest API and SDks for Objective C(iOS ) and Java (Android) and also JavaScript. So, here i am going to show how we can use ACS APIs in PhoneGap application.

Appcelerator Titanium
PhoneGap Logo with Windows Phone Android iOS Bada Blackberry

PhoneGap is another best solutions for cross platform mobile application development. Using PhoneGap we can develop apps for not only iOS, Android. even we can develop for Windows Phone, BlackBerry, Bada, Nokia, and Web OS… Because PhoneGap just need a Web browser control. So, Most of the smartphones supports HTML5 things. So, create for multiple  platforms PhoneGap is best solution. But it have some drawback like slow in scrolling and etc.. . Where Titanium good best in Android and iOS devices.

Here is steps to create PhoneGap app with Titanium ACS API

–> Create ACS Application, go to appcelerator.com and login with your developer account and go to my apps page there you can see ACS only. Click on that

Create Titanium ACS App

–> Set name and description

Create ACS App with name–> It will take you to the APP page. You can also go after going to My APPs and in your Applications area you can see Manage ACS. Click on that it will take to that page.

–> In that Application page you can see APP Key and OAuth Consumer Key and OAuth Secret key. This are very useful when your working with ACS APIs in PhoneGap.

–> Go to XCode in OS X (Same HTML file you can use in Android). Create PhoneGap Application.

–> Remember about White List. Here I am allowing all domains.

PhoneGap External Hosts White ListClick on PhoneGap.Plist file and select ExtrtnalHosts and then add item 0 value with just * .  * means it allows all domains.

–> Now Create UI. I Used Jquery Mobile. It is another awesome JavaScript framework based on jQuery. with effects and animations by default.

this is how I design

UI in PhoneGap Using jQuery MobileYou can Get this HTML file Code here https://github.com/rish7/TiGap/blob/013bbe39bf6e9d5ade15f479d5a3786b1cc5a1ef/www/index.html

–> To contact with Ti ACS we need Cocoafish Javascript. http://sdk.cocoafish.com/js/cocoafish-1.2.min.js Same thing you can see in that HTML code

–> As I said above here we are going to using APP key or oAuth details

If you planing with APP Key

var sdk = new Cocoafish(‘/***YOUR ACS APP KEY HERE***/’);

or if you want to go with OAuth

var sdk = new Cocoafish(‘/***oAuth Consumer KEY HERE***/’,’/***oAuth Secret KEY HERE***/’);

Then create a Data variable to set need input values in that ready to send with sendRequest method call.

sdk.sendRequest(‘users/create.json’, ‘POST’, data, callback);

in this above I am send user Data to create. So, i used users/create.json. If we are going to create new event. Then events/create.json and send needed data with POST request (or whatever it is) with data object and callback function. This Call back function with fire when the actions completed with success or failure result. using Data.meta you can get the information about success call. you can get the full HTML code from my GITHUB https://github.com/rish7/TiGap/

Enjoy while coding and sharing…!

Leave a Reply