11/19/2018 05 | App Model & Storage © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Course Topics Building Windows Store Apps for iOS Developers Jump Start 01 | Introduction to the Windows Store Platform and the tools 02 | C# for Objective-C developers 03 | Async programming & Networking intro Meal Break, around noon PST 45 to 60 mins 04 | Introduction to XAML & UI Patterns for XAML apps 05 | App Model & Storage 06 | Contracts 07 | Notifications 08 | Windows Store APIs
Windows Store app acquisition Windows Store backend Package Manager Windows Store install Execution Engine Extension Handler stage Single instance store register Registration Information
Building blocks of an app package App Manifest contains all information needed to deploy the app Blockmap contains hashes of all files within the app package Signature validates the integrity of the app package AppXManifest.xml BlockMap Signature Zip Central Directory Files / Assets .appx package
Inside the App Bundle - iOS
Inside the App Package - Windows
App manifest and capabilities Explicitly declares the app integration endpoints File capabilities (music/pictures/videos/documents libraries, removable storage) Devices (webcam, microphone, location, sms, proximity); extensible to new device classes Network and identity (internet, private network, credentials) File type associations App contracts (search, share, etc.) Contained in appxmanifest.xml; Visual Studio provides editor
Process Isolation Process1 Process2 OS Contracts Direct APIs Brokers 11/19/2018 Process Isolation Process1 Local context Web context AppData Local Temp Roaming Process2 Local context Web context AppData Local Temp Roaming Contracts Direct APIs Brokers OS User data Devices Communications Handlers Tiles Cryptography … … © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
demo Capabilities 11/19/2018 12:03 AM © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
App Lifecycle and States iOS Apps Windows Store Apps State Visible Receives Events Executes Code Not Running No Active Yes Inactive Mostly Background Suspended State Visible Receives Events App Executes Code NotRunning No Running Yes (No Necessary Equivalent) (Accomplished by Background Tasks) Suspended Terminated ClosedByUser
Windows Store App Lifecycle .appx package
Process State Transitions App gets 5s to handle suspend App is not notified before termination Running App suspending Suspended App Terminated App User Launches App Low Memory resuming Apps are notified when they have been resumed Splash screen Code gets to run No code runs App not running
Process State Transitions 11/19/2018 Process State Transitions App gets 5s to handle suspend App is not notified before termination Running App suspending Suspended App Terminated App User Launches App Low Resources resuming Apps are notified when they have been resumed Splash screen Code gets to run No code runs App not running © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Process State Transitions - Simulation App 1 App 2 App 3 … App N Running Apps suspend after a short delay Apps resume instantly from suspend Suspended App terminated under memory pressure without notification Terminated
Global State Management with SuspensionManager Saving MyGame.Common.SuspensionManager.SessionState["gameStatus"] = GameViewModel.CurrentGameStatus; Restoring GameViewModel.CurrentGameStatus = MyGame.Common.SuspensionManager.SessionState["gameStatus"] as GameStatus; .appx package
The Application.Suspending Event App.xaml.cs public App() { this.InitializeComponent(); this.Suspending += OnSuspending; } private async void OnSuspending(object sender, SuspendingEventArgs e) var deferral = e.SuspendingOperation.GetDeferral(); //serializes Page States and SessionState to local StorageFile await SuspensionManager.SaveAsync(); deferral.Complete(); .appx package
Page State Management with SuspensionManager .appx package
Page State Management with SuspensionManager LayoutAwarePage Code Behind - Saving protected override void SaveState(Dictionary<String, Object> pageState) { pageState.Add("greetingOutputText", greetingOutput.Text) } LayoutAwarePage Code Behind - Restoring protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState) { if (pageState == null) //Do Page State initialization else greetingOutput.Text = pageState["greetingOutputText"].ToString(); } .appx package
Restoring State in Windows Store Apps .appx package
Storing User Preferences iOS - NSUserDefaults [[NSUserDefaults standardUserDefaults] setObject:@”ejeffers” forKey:MYAppDefaultsUsername]; Windows Store Apps – Local Settings ApplicationDataContainer settings = ApplicationData.Current.LocalSettings; settings.Values[”Username"] = ”ejeffers"; Windows Store Apps – Roaming Settings ApplicationDataContainer settings = ApplicationData.Current.RoamingSettings; settings.Values[”Username"] = ”ejeffers";
demo Suspending and Resuming 11/19/2018 12:03 AM © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Application Activations Abbreviated iOS activations Windows Store Apps Activations .appx package
Activation By Contract .appx package
Application Activations – Entry Points Windows Store App Activations .appx package
The Background Task Contract
Background Tasks: Registration private void RegisterBackgroundTask() { BackgroundTaskBuilder builder = new BackgroundTaskBuilder(); builder.Name = "FlickrBackgroundSearchTask"; builder.TaskEntryPoint = "FlickrBackgroundTasks.FlickrSearchTask"; IBackgroundTrigger trigger = new TimeTrigger(15, true); builder.SetTrigger(trigger); IBackgroundCondition condition = new SystemCondition(SystemConditionType.InternetAvailable); builder.AddCondition(condition); IBackgroundTaskRegistration task = builder.Register(); }
Background Tasks: A Simple Implementation namespace BackgroundTasks { public sealed class FlickrSearchTask : IBackgroundTask async void Run(IBackgroundTaskInstance taskInstance) var _deferral = taskInstance.GetDeferral(); HttpResponseMessage response = await client.GetAsync(queryUrl); String jsonString = await response.Content.ReadAsStringAsync(); await FileIO.WriteTextAsync(currentSearchResultsFile, jsonString); updateLiveTile(); _deferral.Complete(); }
Background Tasks: Background Task Flow
Background Tasks: Trigger Types Trigger name Description TimeTrigger Trigger Runs on a Timer (15 minute minimum period) PushNotificationTrigger A Push Notification was received for the App ControlChannelTrigger Chat Programs, Audio Lock Screen Triggers Trigger name Description InternetAvailable The Internet becomes available. NetworkStateChange A network change such as a change in cost or connectivity occurs. OnlineIdConnectedStateChange Online ID associated with the account changes. SmsReceived A new SMS message is received by an installed mobile broadband device. TimeZoneChange The time zone changes on the device (for example, when the system adjusts the clock for daylight saving time). System Triggers (non-lock screen)
Background Tasks: Resource Limits CPU Quota Example Wifi Quota (~1Mbps on battery)
Recap: App Model App Package and Model Process Lifecycle 11/19/2018 Recap: App Model App Package and Model Process Lifecycle Background Tasks Declare Capabilities in AppxManifest Save State with Suspending Event using Suspension Manager Use Background Tasks to keep app fresh when not running © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.