Skip to content

Commit

Permalink
Merge pull request #2916 from xamarin/master
Browse files Browse the repository at this point in the history
[xamarin] iOS article updates
  • Loading branch information
David Wrede committed Mar 3, 2015
2 parents a726a73 + e638087 commit f570d79
Show file tree
Hide file tree
Showing 11 changed files with 413 additions and 286 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 47 additions & 46 deletions articles/partner-xamarin-mobile-services-ios-get-started-data.md
@@ -1,19 +1,19 @@
<properties
pageTitle="Add Mobile Services to an existing app (Xamarin.iOS) - Azure Mobile Services"
description="Learn how to store and access data from your Azure Mobile Services Xamarin.iOS app."
documentationCenter="xamarin"
authors="lindydonna"
manager="dwrede"
services="mobile-services"
<properties
pageTitle="Add Mobile Services to an existing app (Xamarin.iOS) - Azure Mobile Services"
description="Learn how to store and access data from your Azure Mobile Services Xamarin.iOS app."
documentationCenter="xamarin"
authors="lindydonna"
manager="dwrede"
services="mobile-services"
editor=""/>

<tags
ms.service="mobile-services"
ms.workload="mobile"
ms.tgt_pltfrm=""
ms.devlang="dotnet"
ms.topic="article"
ms.date="09/24/2014"
<tags
ms.service="mobile-services"
ms.workload="mobile"
ms.tgt_pltfrm=""
ms.devlang="dotnet"
ms.topic="article"
ms.date="09/24/2014"
ms.author="donnam"/>

# Add Mobile Services to an existing app
Expand All @@ -26,21 +26,21 @@ This topic shows you how to use Azure Mobile Services to leverage data in a Xama
This tutorial walks you through these basic steps:

1. [Download the Xamarin.iOS app project][GitHub]
1. [Download the Xamarin.iOS app project][GitHub]
2. [Create the mobile service]
3. [Add a data table for storage]
4. [Update the app to use Mobile Services]
5. [Test the app against Mobile Services]

This tutorial requires the [Azure Mobile Services Component], [XCode 5.0][Install Xcode], [Xamarin.iOS], and iOS 5.0 or later versions.
This tutorial requires the [Azure Mobile Services Component], [XCode 6.0][Install Xcode], [Xamarin.iOS], and iOS 7.0 or later versions.

> [AZURE.IMPORTANT] To complete this tutorial, you need an Azure account. If you don't have an account, you can create a free trial account in just a couple of minutes. For details, see [Azure Free Trial](http://www.windowsazure.com/pricing/free-trial/?WT.mc_id=A643EE910&amp;returnurl=http%3A%2F%2Fwww.windowsazure.com%2Fen-us%2Fdevelop%2Fmobile%2Ftutorials%2Fget-started-with-data-xamarin-ios%2F"%20target="_blank).
<h2><a name="download-app"></a>Download the GetStartedWithData project</h2>

This tutorial is built on the [GetStartedWithData app][GitHub], which is a Xamarin.iOS app. The UI for this app is identical to the app generated by the Mobile Services Xamarin.iOS quickstart, except that added items are stored locally in memory.
This tutorial is built on the [GetStartedWithData app][GitHub], which is a Xamarin.iOS app. The UI for this app is identical to the app generated by the Mobile Services Xamarin.iOS quickstart, except that added items are stored locally in memory.

1. Download the [GetStartedWithData app][GitHub].
1. Download the [GetStartedWithData app][GitHub].

2. In Xamarin Studio, open the downloaded project and examine the **TodoService** class.

Expand Down Expand Up @@ -74,30 +74,30 @@ To be able to store app data in the new mobile service, you must first create a

![][6]

This creates a new storage table **TodoItem** with the default permissions set, which means that any user of the app can access and change data in the table.
This creates a new storage table **TodoItem** with the default permissions set, which means that any user of the app can access and change data in the table.

> [AZURE.NOTE] The same table name is used in Mobile Services quickstart. However, each table is created in a schema that is specific to a given mobile service. This is to prevent data collisions when multiple mobile services use the same database.

4. Click the new **TodoItem** table and verify that there are no data rows.

5. Click the **Columns** tab and verify that there is only a single **id** column, which is automatically created for you.

This is the minimum requirement for a table in Mobile Services.
This is the minimum requirement for a table in Mobile Services.

> [AZURE.NOTE] When dynamic schema is enabled on your mobile service, new columns are created automatically when JSON objects are sent to the mobile service by an insert or update operation.

You are now ready to use the new mobile service as data storage for the app.

<h2><a name="update-app"></a>Update the app to use the mobile service for data access</h2>

Now that your mobile service is ready, you can update the app to store items in Mobile Services instead of the local collection.
Now that your mobile service is ready, you can update the app to store items in Mobile Services instead of the local collection.

1. If you don't already have **Azure Mobile Services** listed in the Components folder, you can get it by right-clicking **Components**, choosing **Get More Components** and then searching for **Azure Mobile Services**.

2. In the Solution view in Xamarin Studio, open the **TodoService** class and uncomment the following `using` statement:

using Microsoft.WindowsAzure.MobileServices;

3. In the Management Portal, click **Mobile Services**, and then click the mobile service you just created.

4. Click the **Dashboard** tab and make a note of the **Site URL**, then click **Manage keys** and make a note of the **Application key**.
Expand Down Expand Up @@ -126,40 +126,40 @@ Now that your mobile service is ready, you can update the app to store items in
9. Uncomment the following lines in the **TodoService** constructor:

// TODO:: Uncomment these lines to use Mobile Services
client = new MobileServiceClient(Constants.ApplicationURL, Constants.ApplicationKey).WithFilter(this);
todoTable = client.GetTable<TodoItem>();
client = new MobileServiceClient(Constants.ApplicationURL, Constants.ApplicationKey).WithFilter(this);
todoTable = client.GetTable<TodoItem>();

This creates an instance of the Mobile Services client and creates the TodoItem table instance.

10. Uncomment the following lines in the **RefreshDataAsync** method in **TodoService**

// TODO:: Uncomment these lines to use Mobile Services
try
{
// This code refreshes the entries in the list view by querying the TodoItems table.
// The query excludes completed TodoItems
Items = await todoTable
.Where (todoItem => todoItem.Complete == false).ToListAsync();
}
catch (MobileServiceInvalidOperationException e)
{
Console.Error.WriteLine (@"ERROR {0}", e.Message);
return null;
}
// TODO:: Uncomment these lines to use Mobile Services
try
{
// This code refreshes the entries in the list view by querying the TodoItems table.
// The query excludes completed TodoItems
Items = await todoTable
.Where (todoItem => todoItem.Complete == false).ToListAsync();
}
catch (MobileServiceInvalidOperationException e)
{
Console.Error.WriteLine (@"ERROR {0}", e.Message);
return null;
}

This creates a query to return all tasks that have not yet been completed.

11. Locate the **InsertTodoItemAsync** method, and uncomment the following line:

await todoTable.InsertAsync(todoItem);

This code sends an insert request to the mobile service.

13. Locate the **CompleteItemAsync** method, and uncomment the following line:

await todoTable.UpdateAsync(item);
This code removes TodoItems after they are marked as completed.

This code removes TodoItems after they are marked as completed.

Now that the app has been updated to use Mobile Services for backend storage, it's time to test the app against Mobile Services.

Expand All @@ -178,17 +178,17 @@ Now that the app has been updated to use Mobile Services for backend storage, it
4. Click the **Data** tab, then click **Browse**.

![][9]

Notice that the **TodoItem** table now contains data, with id values generated by Mobile Services, and that columns have been automatically added to the table to match the TodoItem class in the app.

This concludes the **Get started with data** tutorial for Xamarin.iOS.

## Get completed example
Download the [completed example project]. Be sure to update the **applicationURL** and **applicationKey** variables with your own Azure settings.
Download the [completed example project]. Be sure to update the **applicationURL** and **applicationKey** variables with your own Azure settings.

## <a name="next-steps"> </a>Next steps

This tutorial demonstrated the basics of enabling an iOS app to work with data in Mobile Services.
This tutorial demonstrated the basics of enabling an iOS app to work with data in Mobile Services.

Next, consider completing one of the following tutorials that is based on the GetStartedWithData app that you created in this tutorial:

Expand All @@ -200,10 +200,10 @@ Next, consider completing one of the following tutorials that is based on the Ge

Once you have completed the data series, try these other iOS tutorials:

* [Get started with authentication]
* [Get started with authentication]
<br/>Learn how to authenticate users of your app.

* [Get started with push notifications]
* [Get started with push notifications]
<br/>Learn how to send a very basic push notification to your app with Mobile Services.

<!-- Anchors. -->
Expand Down Expand Up @@ -243,3 +243,4 @@ Once you have completed the data series, try these other iOS tutorials:
[Azure Mobile Services Component]: http://components.xamarin.com/view/azure-mobile-services/

[completed example project]: http://go.microsoft.com/fwlink/p/?LinkId=331302
[Xamarin.iOS]: http://xamarin.com/download

0 comments on commit f570d79

Please sign in to comment.