What does the Titanium SDK upgrade to version 2.0 carry?

I welcome all the supporters and admirers of cross-platform development of mobile applications using the Titanium framework. On April 16, 2012, Appcelerator announced the upgrade of the Titanium Mobile SDK to version 2.0.1, along with the upgrade of Titanium Studio all to the same version 2.0.1. A little more details under the cut.


According to the developers from Appcelerator, in addition to fixing more than 700 bugs identified in previous versions, Titanium Mobile SDK 2.0.1 is based on the strengths of the previous version 1.8, and also includes a number of interesting innovations:
  • Integrated with Appcelerator Cloud Services (formerly known as CocoaFish);
  • Application markup system changed
  • a higher degree of cross-platform development of applications for Android and iPhone;
  • mobile Web (formerly HTML5 platform) release candidate;
  • more flexible functionality in the field of geolocation;
  • support for Xcode 4.3 and iOS 5.1;

I would like to dwell on such goodies as integration with the Appcelerator Cloud Service (ACS).

It's no secret that the comfortable use of mobile devices involves 2 things:
  1. Extensive mobile client capabilities, including both general and device-specific functionality.
  2. Cloud-related capabilities that allow the end user to access content without being tied to a device, as well as allowing other users to interact with devices and access their local content. Now it is possible with ACS.

Appcelerator Cloud Services provides the developer with a wide range of automatically scalable networking capabilities. Tasks such as push notifications, user authorization, managing user photos, photo collections, receiving and updating user status, which usually require server programming or integration with several SDKs, are now carried out through a single plug-in interface .

According to the developers of Titanium, they took care of the stable functioning of databases, file vaults, search engines and application stacks, so that we can focus on what is really important: our applications and the users of these applications.
Today out of the box are available:
  • Push notifications;
  • User management (creation, authorization, request for user information, etc.);
  • Various manipulations with user photos (upload to server, storage, etc.);
  • Places (rich location storage);
  • Social integration;
  • File Storage (Beta);
  • Chekins (check-ins);
  • User status updates;
  • Chats
  • Friends (Beta)
  • Ratings and reviews;
  • Discussion forums;
  • Event Organization (Beta);
  • Messages (Beta);
  • Data storage in a key-value format;

Currently, features marked as beta are not available from the Titanium.Cloud module, but they can be accessed using the REST API.

In addition, ACS is available to all mobile application developers, regardless of the technology with which these applications are developed. Those. no matter what we create our application with, be it Titanium, Objective-C, Java, Sencha Touch or PhoneGap. Any technology that allows you to make an HTTP request can easily use ACS as a backend server.

In order to use ACS in our application, we need to complete the following four steps:

1) Register an application in Appcelerator Cloud Services


If we create a new project in Titanium Studio and at the same time activate the corresponding checkbox, the application in Appcelerator Cloud Services is automatically registered. You can see it on the My Applications page in our account at the Appcelerator Developer Center . If the checkbox was not activated, then you can manually register the application later all on the same page " my applications ".

When registering the application, unique OAuth Consumer Key, OAuth Secret and App Key will be generated, which we will need to use in the further development of the application.

2) Connecting the Appcelerator Cloud Services module


ACS support is built into Titanium. Nevertheless, in order to use it, we must use the require () directive in any file convenient for us to connect the ACS module to our project:
var Cloud = require('ti.cloud');
Cloud.debug = true;  // опционально. Для продакшена тут нужно поставить false

Also, do not forget about tiapp.xml and make sure that the following directive is present there:
ti.cloud


3) Authentication


To ensure the security of connections and in order to exclude options in which someone pretends to be us and sends requests to ACS, our application must prove that it has the right to communicate with ACS. Secure access is provided through two-step OAuth authentication . This is the process by which the Consumer Key and OAuth Secret are used to “sign” each request of our application. When the ACS server receives the request, OAuth Secret is used along with the data provided in the request to calculate the verification signature. If the sent and calculated signatures match, the request will be processed.
In order for our application to successfully “introduce itself” to the server, add the following lines to the tiapp.xml file:
get_from_app_admin_pageget_from_app_admin_pageget_from_app_admin_page


4) Directly using the API in the application code


A few examples:

4.1) Creating a user:

Cloud.Users.create({
    username: username.value,
    password: password.value,
    password_confirmation: confirmPassword.value,
    first_name: firstName.value,
    last_name: lastName.value
}, function (e) {
    if (e.success) {
		// пользователь создан успешно
    } else {
               // обработка ошибки
    }
});

4.2) Publication of the photo:

// предполагается, что у нас уже есть фото. Не важно каким способом мы его получили.
// collectionID это ID необходимый для группировки фотографий в облаке
Cloud.Photos.create({
    photo: photo,
    collection_id: collectionID,
    'photo_sync_sizes[]': 'small_240'
}, function (e) {
    if (e.success) {
	 // тут можно обнулить наши объекты для очистки памяти
        photo = null;
        collectionID = null;
    } else {
        // обработчик ошибки
    }
});

4.3) Connecting FaceBook Login to our application:

//код для реализации модуля Facebook в приложении не показан
// функция обработчик, которая будет логинить пользователя
function updateLoginStatus() {
    if (Ti.Facebook.loggedIn) {
        label.text = 'Logging in to ACS as well, please wait...';
        Cloud.SocialIntegrations.externalAccountLogin({
            type: 'facebook',
            token: Ti.Facebook.accessToken
        }, function (e) {
            if (e.success) {
                var user = e.users[0];
                alert('Logged in! You are now logged in as ' + user.id);
            }
            else {
                error(e);
            }
        });
    }
    else {
        label.text = 'Please login to Facebook.';
    }
}
//повесим обработчик на события авторизации и деавторизации пользователя в FaceBook
Ti.Facebook.addEventListener('login', updateLoginStatus);
Ti.Facebook.addEventListener('logout', updateLoginStatus);
// добавим кнопку логина Facebook
win.add(Ti.Facebook.createLoginButton({
    top: 10
}));


On the one hand - some advantages! So far, the only minus detected is that the free version of ACS is available only until June 1, 2012. This is also reported in one of the posts of the developers of Appcelerator.

There is a strong impression that the guys from Appcelerator in the field of organizing application development are persistently chasing the guys from Apple. Judge for yourself: each developer must register, if he wants to use Titanium, he has his own development environment, thanks to which each developed application is recorded and statistics are kept on it, there is a module store, etc.

That, in fact, is all. Thanks for attention.

Sources:

Also popular now: