Presentation is loading. Please wait.

Presentation is loading. Please wait.

Xamarin Development with

Similar presentations


Presentation on theme: "Xamarin Development with"— Presentation transcript:

1 Xamarin Development with
Azure Mobile Services July

2 Information www.linkedin.com/in/david-silver-1b637924 David Silver
Great Xamarin and Azure Tutorial:

3 Summary What this will cover Creating a new Xamarin Forms app
Creating a new Azure Mobile Service Connecting the app to the mobile service Enabling authentication Enabling offline sync

4 What is Xamarin? Cross platform solution for writing native mobile apps with C# Xamarin.Forms allows you build a native UI shared across your platforms. All controls are mapped to native controls at runtime A Mac is needed for iOS development Mac can also build Android apps

5 Create New Azure Mobile Services
Create/login to Azure account Click Search for Mobile App Click Mobile App > Create Enter an App name and Resource Group Choose your App Service plan – free tier is fine for this Click Create Once deployed go to the newly created resource

6 Quickstart Mobile Services
Go to Quickstart > Xamarin.Forms Do step 1 to setup a new database Free tier is fine for this

7 Creating Xamarin Forms Backend
File > New > Project > Visual C# Web > ASP.NET Web Application > Azure Mobile App In order to have the tables be in Azure your backend project needs A DbSet within the DbContext A DTO for your table A table controller The Azure Mobile App Project contains one of each of these Your DTO should use Azure Mobile Entity Data as it’s base class to take advantage of offline sync

8 Creating Xamarin Forms Backend Contd.
For automatic migrations Enable migrations Add initial migration Replace the DbInitializer in Startup.MobileApp with a database migrator Replace MobileAppConfiguration with AddTablesWithEntityFramework Configure a SqlGenerator in the Migration Configuration file Publish the backend to Azure

9 Creating Xamarin Forms App
Right click solution > Add > New Project… Under Visual C# Cross-Platform > Cross Platform App(Xamarin) Blank App, Xamarin.Forms, Shared or PCL Article on Shared VS PCL: MVVM pattern - create Models, Pages(Views), & ViewModels folders in PCL

10 Preparing For Azure Mobile Services
Add the following nuget packages: Microsoft.Azure.Mobile.Client(3.1.0), Microsoft.Azure.Mobile.Client.SQLiteStore(3.1.0), SQLitePCL(latest) (Original by Microsoft Open Technologies, Inc.) If needed update Xamarin.Forms ONLY

11 Setup Mobile Project Create Interfaces
Cloud service interface is a singleton for auth and offline sync Create services that implement the interfaces Create models Prep Offline Sync – Create a base model – string Id, DateTimeOffset UpdatedAt, DateTimeOffset CreatedAt, byte array Version (mimics Entity Data except Deleted field) Copy azure site URL Set your client to your azure URL – Be sure to use https

12 Create the Views (Pages) and ViewModels
Add XAML Content Pages to Pages Folder Additional info on MVVM with Xamarin: Setup binding to ViewModel Add XAML UI Create BaseViewModel – ViewModels should implement INotifyPropertyChanged Add ViewModel to ViewModels folder Setup ViewModel – Use observable collections instead of list for collections that will change

13 Add Authentication Set the Authorize attribute in the backend
Choose your auth provider Login in their developer portal and setup your app Add your secret and other info to Azure Portal in your App Service Settings > Authentication/Authorization Setup ILoginProvider to allow for cross platform implementation Add Login to ICloudService Implement ICloudService Add platform specific code – Init the login provider in MainActivity.cs

14 Enable Offline Sync Add “Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();” to MainActivity.cs and AppDelegate.cs above the Xamarin Form init Enable internet permissions on Android Setup the Initialize Setup offline sync table – local SQLite store Setup Pull to bring in online changes – Use query name to allow for incremental updates Setup Sync method to push pending local changes and pull server changes Place the Sync method on your refresh, saving, deleting commands

15 Enable Offline Sync Contd.
Add “Xam.Plugin.Connectivity” nuget package to check for connectivity If no connectivity, return before doing push/pull operations Setup conflict resolver

16 Summary Create and setup ASP .Net backend – Azure Mobile App
Setup Azure mobile services including authentication Create and setup Xamarin.Forms app Enable offline sync and authentication in the mobile app


Download ppt "Xamarin Development with"

Similar presentations


Ads by Google