- Adding ArrowDB to your Titanium project
- Importing the module
- Authenticating your application
- Push notifications
- Using the ArrowDB APIs
- Importing and running the Ti.Cloud sample application
The ArrowDB APIs are supported in Titanium using the
ti.cloud module, an optional module which is packaged with the Titanium SDK.
When new APIs are added to ArrowDB, they may not be immediately available in the Cloud module. See the module API reference for a list of supported objects and methods.
Adding ArrowDB to your Titanium project
This section describes how to add ArrowDB to a Titanium application. If you don't have an existing ArrowDB datasource, Studio can create one for you.
If you are using the CLI, the CLI automatically creates an ArrowDB datasource for you.
Adding ArrowDB to a new Titanium application
If you are using Studio to create a new Titanium application, you can create a new ArrowDB datasource at the same time:
- Click File > New > Mobile Project to start the new project wizard.
- Choose a template and click Next.
- On the next screen, make sure Enable Appcelerator Platform Services checked.
- Enter the project name and ID and click Finish.
This creates a new Titanium application and a new ArrowDB datasource, and configures the Titanium project to access ArrowDB.
Adding ArrowDB to an existing Titanium application
If you have an existing Titanium project in Studio, and want to create a new ArrowDB datasource for it:
- Open the project's
tiapp.xmland switch to the Overview tab.
- Click to Enable Services.
Adding an existing ArrowDB application to a Titanium project
If you have already created an ArrowDB datasource, you can add it to a Titanium project by editing the
tiapp.xml file. You'll need the application key generated when you created the ArrowDB datasource.
Open the project's
tiapp.xmland switch to the tiapp.xml (source view) tab.
Add the following entries to the file:
<modules>element in the file, and add the following:
If there is no
<modules>element, add the following inside the
(This element is usually placed just above the
Virtual private cloud configuration
If you are using a virtual private cloud (VPC), you need to configure your Arrow Push dispatcher URL in order to send push notifications with GCM. In the
tiapp.xml file, add the
acs-push-api-url application property and set the node text to the push dispatcher URL provided to you. The URL may be the same as your custom ArrowDB endpoint and have deployment-specific settings, that is, two URLs--one for production and another for the development environment.
Importing the module
ArrowDB support is baked into Titanium. However, you must include the cloud services module into your project to use ArrowDB functionality. In your
app.js (or other suitable file), include the
require() statement as shown here:
Authenticating your application
To keep your ArrowDB data secure from unauthorized access, your application must prove that it is allowed to communicate with ArrowDB in each HTTP request. The Titanium Cloud module passes the ArrowDB application key, configured in the project's
tiapp.xml file, with each request over SSL.
For more information, see Authentication.
To setup your Titanium application to use push notifications, see Push Notification guide.
Using the ArrowDB APIs
The response callback receives a single object, which is a slightly modified version of the REST response object. The REST response contains two objects:
meta : Object -Response metadata, such as success or failure, error messages, pagination information.
response : Object -Response data specific to the call. For example, if you search for places, the response object contains an array of places.
The module's response object includes any properties from
response at the top level of the object. For example, if the REST response includes
response.places, this is included as
The module's response object also includes the following fields:
meta : Object -Metadata from the REST response.
success : Boolean -True if the request succeeded (that is,
meta.status == "ok").
error : Boolean -True if the request failed (
meta.status != "ok").
message : String -Error message, if available.
code : Number -Error code, if available.
With over 25 APIs available for you to use, we obviously can't cover them all here. But let's take a look at a couple of examples.
Create a user:
Post a photo to a photo collection. To post a photo to a collection, you need to create the collection first using PhotoCollections.
Linking a Facebook login with your app. You must already be logged in using the Titanium Facebook module before calling the
For more examples, see the ArrowDB API documentation.
Importing and running the Ti.Cloud sample application
The Titanium Cloud module also includes a sample application that demonstrates each of the ArrowDB request types.
To import and run the Ti.Cloud sample application:
- In Studio, select File > New > Mobile App Project.
- Select the Classic application type with the Default Project template.
- In the New Mobile App Project dialog, enter values for the Project Name and App ID fields, and check the option to Enable Appcelerator Platform Services.
- Click Finish.
From your desktop, navigate to the following folder, where
<latest_version>is the folder containing the latest SDK version:
- Windows 7:
- Windows 8:
Select all the folders and files in the example folder and drag them to your project's Resources folder.
- If prompted, select the option to Copy Files and Folders and click OK.
- Click Yes to All when asked if you want to overwrite files.
Open the project's
tiapp.xmlfile and, in the Modules section, add the facebook and ti.cloudpush modules.
tiapp.xmland run the project on the desired device or emulator/simulator.
Once the application is running, try the following:
Create a new user by selecting Users > Create User. Enter a username, password and password confirmation, first name, and last name, then click Create. If the user is created successfully, the following dialog is shown:
View the newly created user in Dashboard:
- Open Dashboard and select your application from the Apps menu.
- Select Cloud > Manage Data, then click Users in the Manage Data Object table. You should see the user you created listed in the Users table.