Build a Xamarin.iOS app with Azure Mobile Apps

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

You must complete this tutorial before other Xamarin.iOS tutorials using the Mobile Apps feature in Azure App Service.

Prerequisites

To complete this tutorial, you need:

You can complete this tutorial on Mac or Windows, but you must have a Mac available for iOS compilations.

Download the Xamarin.iOS quickstart project

The Xamarin.iOS quickstart project is located in the samples/xamarin-ios folder of the azure/azure-mobile-apps GitHub repository. You can download the repository as a ZIP file, then unpack it. The files will be created in the azure-mobile-apps-main folder.

Once downloaded, open a Terminal and change directory to the location of the files.

Deploy the backend service

To deploy the quickstart service, first login to Azure with the Azure CLI:

az login

A web browser will be opened to complete the authorization.

If necessary, select a subscription.

Create a resource group

Type the following to create a resource group:

az group create -l westus -n zumo-quickstart

This command creates a resource group called zumo-quickstart to hold all the resources we create. Replace westus with another region if you do not have access to the westus region or you prefer a region closer to you.

Deploy the backend to Azure

The service is composed of the following resources:

  • An App Service Hosting Plan on the Free plan.
  • A web-site hosted within the App Service Hosting plan.
  • An Azure SQL server.
  • An Azure SQL database in the Basic tier (incurs cost).

The Azure SQL database is the only resource that incurs cost. For details, see Pricing.

To deploy the resources, type the following commands:

cd samples/nodejs
az deployment group create -n ZumoQuickstart -g zumo-quickstart --template-file ./azuredeploy.json

Once complete, run the following command to see the outputs:

az deployment group show -n ZumoQuickstart -g zumo-quickstart --query properties.outputs

This command shows information about your deployment that you need in developing your mobile application. The database username and password are useful for accessing the database through the Azure portal. The name of the App Service is used below, and the public endpoint is embedded in your code later on.

Finally, deploy the Azure Mobile Apps server to the created App Service:

az webapp deployment source config-zip -g zumo-quickstart --name zumo-XXXXXXXX --src ./zumoserver.zip

Replace zumo-XXXXXXXX with the name of your App Service; shown in the list of outputs. Within 2-3 minutes, your Azure Mobile Apps server will be ready to use. You can use a web browser to confirm that the backend is working. Point your web browser to your public endpoint with /tables/TodoItem appended to it (for example, https://zumo-XXXXXXXX.azurewebsites.net/tables/TodoItem). The browser will display an error about a missing X-ZUMO-VERSION parameter if the server is working properly.

Deleting the resources

Once you have completed the quickstart tutorial, you can delete the resources with az group delete -n zumo-quickstart.

The tutorial is comprised of three parts (including this section). Do not delete the resources before completing the tutorial.

Configure the Xamarin.iOS quickstart project

Open the ZumoQuickstart solution in Visual Studio (located at samples/xamarin-ios). Edit the Constants.cs class to replace the BackendUrl with your backend URL. For example, if your backend URL was https://zumo-abcd1234.azurewebsites.net, then the file would look like this:

namespace ZumoQuickstart
{
    /// <summary>
    /// Constants used to configure the application.
    /// </summary>
    public static class Constants
    {
        /// <summary>
        /// The base URL of the backend service within Azure.
        /// </summary>
        public static string BackendUrl { get; } = "https://zumo-abcd1234.azurewebsites.net";
    }
}

Save the file.

Run the iOS app

Note

If you are running Visual Studio on Windows, you MUST follow the guide to Pair to Mac. You will receive errors when compiling or running iOS applications without a paired Mac.

The "start" button in the top ribbon may show an iOS device. Ensure that the iPhoneSimulator configuration is selected:

iOS Configuration

Press F5 to build and run the project. The iOS simulator will start, then Visual Studio will install the app, and finally the app will start.

Enter some text in the Add New Item field, then press enter or click the add item button. The item is added to the list. Click on the item to set or clear the "completed" flag.

Quickstart iOS

Next steps

Continue on to implement offline data synchronization.