DISCLAIMER: THIS IS SAMPLE CODE AND NOT PRODUCTION QUALITY CODE!
Before running this sample, the BookService sample needs to be running locally on your computer or published to the cloud. For more information, see BookService
This sample is a client application that makes HTTP requests to the BookService project. You can view, create, edit and delete books stored in a Mongo backend database via the BookService.
This sample runs on either Android 3.0 (API 11) and later or iOS, and was tested against Titanium SDK 3.1.0.GA and Alloy 1.1.2.
This sample provides two sync adapters--REST and Node.ACS. The REST adapter directly makes HTTP requests to the service, while the Node.ACS adapter uses a bindings file generated by the Node.ACS CLI to make JavaScript API calls to access the service.
Clone this repo, create a new Alloy project, then import the cloned repo into the newly created Alloy project.
- From the menu bar, select File > New > Mobile Project. The New Mobile Project wizard appears.
- Select Alloy > Default Alloy Project. Click Next.
- Fill out all fields and click Finish.
- From the menu bar, select File > Import. The Import wizard appears.
- Select General > File System. Click Next.
- For From directory, click Browse, navigate to the cloned repo, then click Open.
- Select the app folder, that is, checkmark the item.
- For Into directory, click Browse, select the newly created project, then click OK.
- Click Finish.
Studio creates a new Alloy project and imports the files into it.
Add the following to the Android manifest section of your tiapp.xml
file:
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<uses-sdk android:minSdkVersion="11" android:targetSdkVersion="11"/>
</manifest>
</android>
Then, modify the model file to use either the REST or ACS sync adapter.
Modify app/model/book.js
to use REST adapter:
- Change the
config.adapter.type
key tobook_rest
. - Change the
config.adapter.base_url
key to the endpoint URL of the BookService, for example,http://localhost:8080/book/
.
Note: You NEED the /book/
part of the URL.
Modify app/model/book.js
to use Node.ACS adapter. Change the config.adapter.type
key to book_acs
.
Add the following key to your tiapp.xml
file and replace the URL with your
endpoint URL for BookService:
<property name="acs-service-baseurl-BookService">https://localhost:8080</property>
Note: You do NOT need the /book/
part of the URL.
Before running the client application, the BookService project either needs to be running locally on your computer or published to the cloud.
In Studio,
- Select your project in the App Explorer or Project Explorer view.
- Click the Run button and select either the Android Emulator or iPhone Simulator.
Studio launches the client application on the selected platform.
The client application uses the native controls of the Android and iOS platform to add a book or refresh the table.
- For Android, use the Menu button to activate the action bar.
Select
Add
to add a book orRefresh
to refresh the view. - For iOS, use the window's right navigation button (
Add
) to add a book and drag the table down to refresh the view.
To close a window, use the Back button on the Android platform and the
window's right navigation button (Close
) on the iOS platform.
To modify or delete a book, click on the book title in the table, then:
- To modify the book, make your modifications and click Save Edits.
- To delete the book, click Remove.