This tutorial shows you how to add a cloud-based backend service to an iOS app using Azure Mobile Services. In this tutorial, you will create both a new mobile service and a simple To do list app that stores app data in the new mobile service. The mobile service that you will create uses the supported .NET languages using Visual Studio for server-side business logic and to manage the mobile service. To create a mobile service that lets you write your server-side business logic in JavaScript, see theJavaScript backend version of this topic.
A screenshot from the completed app is below:
Completing this tutorial requires XCode 4.5 and iOS 5.0 or later versions.
NOTE
To complete this tutorial, you need an Azure account. If you don't have an account, you can sign up for an Azure trial and get up to 10 free mobile services that you can keep using even after your trial ends. For details, see Azure Free Trial.
Create a new mobile service
Follow these steps to create a new mobile service.
- Log into the Management Portal.
- At the bottom of the navigation pane, click +NEW.
- Expand Compute and Mobile Service, then click Create.This displays the New Mobile Service dialog.
- In the Create a mobile service page, select Create a free 20 MB SQL Database, select .NET runtime, then type a subdomain name for the new mobile service in the URL textbox and wait for name verification. Once name verification completes, click the right arrow button to go to the next page.This displays the Specify database settings page.NOTEAs part of this tutorial, you create a new SQL Database instance and server. You can reuse this new database and administer it as you would any other SQL Database instance. If you already have a database in the same region as the new mobile service, you can instead choose Use existing Database and then select that database. The use of a database in a different region is not recommended because of additional bandwidth costs and higher latencies.
- In Name, type the name of the new database, then type Login name, which is the administrator login name for the new SQL Database server, type and confirm the password, and click the check button to complete the process.NOTEWhen the password that you supply does not meet the minimum requirements or when there is a mismatch, a warning is displayed.
We recommend that you make a note of the administrator login name and password that you specify; you will need this information to reuse the SQL Database instance or the server in the future.
You have now created a new mobile service that can be used by your mobile apps.
Download the mobile service to your local computer
Now that you have created the mobile service, download your personalized mobile service project that you can run on your local computer or virtual machine.
- Click the mobile service that you just created, then in the quickstart tab, click iOS under Choose platform and expandCreate a new iOS app.
- If you haven't already done so, download and install Visual Studio Professional 2013, or a later version.
- Click Download under Download and publish your service to the cloud.This downloads the Visual Studio project that implements your mobile service. Save the compressed project file to your local computer, and make a note of where you saved it.
- Also, download your publish profile, save the downloaded file to your local computer, and make a note of where you save it.
Test the mobile service
The mobile service project that you download lets you to run your new mobile service right on your local computer or virtual machine. This makes it easy to debug your service code before you even publish it to Azure.
- Browse to the location where you saved the compressed project files, expand the files on your computer, and open the solution file in Visual Studio.
- Press the F5 key to rebuild the project and start the mobile service locally.A web page is displayed after the mobile service starts successfully.
Publish your mobile service
After testing the client app against the local mobile service, the final stage of this tutorial is to publish the mobile service to Azure and run the app against the live service.
- In Solution Explorer, right-click the mobile service project, click Publish, then in the Publish Web dialog box click Azure Mobile Services.
- Sign in with your Azure account credentials, select your service from Existing Mobile Services, and click OK.Visual Studio downloads your publish settings directly from Azure.
- Click Validate connection to verify that publishing is correctly configured, then click Publish.After publishing succeeds, you will again see the confirmation page that the mobile service is up and running, this time in Azure.
Create a new iOS app
In this section you will create a new iOS app that is connected to your mobile service.
- In the Management Portal, click Mobile Services, and then click the mobile service that you just created.
- In the quickstart tab, click iOS under Choose platform and expand Create a new iOS app.
- If you haven't already done so, download and install Xcode v4.4 or a later version.
- Under Download and run your app, click Download.This downloads the project for the sample To do list application that is connected to your mobile service, along with the Mobile Services iOS SDK. Save the compressed project file to your local computer, and make a note of where you saved it.
Run your new iOS app
The final stage of this tutorial is to build and run your new app.
- Browse to the location where you saved the compressed project files, expand the files on your computer, and open the project file using Xcode.
- Press the Run button to build the project and start the app in the iPhone emulator, which is the default for this project.
- In the app, type meaningful text, such as Complete the tutorial and then click the plus (+) icon.This sends a POST request to the new mobile service hosted in Azure. Data from the request is inserted into the TodoItem table. Items stored in the table are returned by the mobile service, and the data is displayed in the list.
This shows how to run your new client app against the mobile service running in Azure. Before you can test the iOS app with the mobile service running on a local computer, you must configure the Web server and firewall to allow access from your iOS development computer.
Source from
http://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-ios-get-started/?WT.mc_id=zumo_aspnet
No comments :
Post a Comment