Create an Apache Cordova app

Overview

This tutorial shows you how to add a cloud-based backend service to an Apache Cordova mobile app by using an Azure mobile app backend. You create both a new mobile app backend and a simple Todo list Apache Cordova app that stores app data in Azure.

Completing this tutorial is a prerequisite for all other Apache Cordova tutorials about using the Mobile Apps feature in Azure App Service.

Prerequisites

To complete this tutorial, you need the following prerequisites:

You may also bypass Visual Studio and use the Apache Cordova command line directly. Using the command line is useful when completing the tutorial on a Mac computer. Compiling Apache Cordova client applications using the command line is not covered by this tutorial.

Create an Azure mobile app backend

  1. Sign in to the Azure portal.

  2. Click Create a resource.

  3. In the search box, type Mobile Apps.

  4. In the results list, select Mobile App, and then select Create.

  5. Choose a unique App name. This will also be part of the domain name for your App Service.

  6. Select the Subscription for this mobile app.

  7. Under Resource Group, select an existing resource group or create a new one (using the same name as your app).

  8. Click Create. Wait a few minutes for the service to be deployed successfully before proceeding. Watch the Notifications (bell) icon in the portal header for status updates.

Create a database connection and configure the client and server project

  1. Download the client SDK quickstarts for the following platforms:

    iOS (Objective-C) iOS (Swift) Android (Java) Xamarin.iOS Xamarin.Android Xamarin.Forms Cordova Windows (C#)

  2. Azure Mobile Apps support .NET and Node backend SDK. Depending on your app type, download the .NET or Node project for open source repository.

  3. You will have to add a database connection or connect to an existing connection. First, determine whether you’ll create a data store or use an existing one.

  4. Create a new data store : If you’re going to create a data store, use the following quickstart:

    Quickstart: Getting started with single databases in Azure SQL Database

  5. Existing data source : Follow the instructions below if you want to use an existing database connection

    1. SQL Database Connection String format - Data Source=tcp:{your_SQLServer},{port};Initial Catalog={your_catalogue};User ID={your_username};Password={your_password}

      {your_SQLServer} Name of the server, this can be found in the overview page for your database and is usually in the form of “server_name.database.windows.net”. {port} usually 1433. {your_catalogue} Name of the database. {your_username} User name to access your database. {your_password} Password to access your database.

      Learn more about SQL Connection String format

    2. Add the connection string to your mobile app In App Service, you can manage connection strings for your application by using the Configuration option in the menu.

      To add a connection string:

      1. Click on the Application settings tab.

      2. Click on [+] New connection string.

      3. You will need to provide Name, Value and Type for your connection string.

      4. Type Name as MS_TableConnectionString

      5. Value should be the connecting string you formed in the step before.

      6. If you are adding a connection string to a SQL Azure database choose SQLAzure under type.

Download and run the Apache Cordova app

  1. Navigate to the solution file in the client project (.sln) and open it using Visual Studio.

  2. In Visual Studio, choose the solution platform (Android, iOS, or Windows) from the drop-down next to the start arrow. Select a specific deployment device or emulator by clicking the drop-down on the green arrow. You can use the default Android platform and Ripple emulator. More advanced tutorials (for example, push notifications) require you to select a supported device or emulator.

  3. Open the file ToDoActivity.java in this folder - ZUMOAPPNAME/app/src/main/java/com/example/zumoappname. The application name is ZUMOAPPNAME.

  4. Go to the Azure portal and navigate to the mobile app that you created. On the Overview blade, look for the URL which is the public endpoint for your mobile app. Example - the sitename for my app name "test123" will be https://test123.azurewebsites.net.

  5. Go to the index.js file in ZUMOAPPNAME/www/js/index.js and in onDeviceReady() method, replace ZUMOAPPURL parameter with public endpoint above.

    client = new WindowsAzure.MobileServiceClient('ZUMOAPPURL');

    becomes

    client = new WindowsAzure.MobileServiceClient('https://test123.azurewebsites.net');

  6. To build and run your Cordova app, press F5 or click the green arrow. If you see a security dialog in the emulator requesting access to the network, accept it.

  7. After the app is started on the device or emulator, type meaningful text in Enter new text, such as Complete the tutorial and then click the Add button.

The backend inserts data from the request into the TodoItem table in the SQL Database, and returns information about the newly stored items back to the mobile app. The mobile app displays this data in the list.

You can repeat steps 3 through 5 for other platforms.