44
Silverlight apps on Windows Phone 8.1 Building Apps for Windows Phone 8.1 Jump Start Silverlight 8.1 Phone Only

23 silverlight apps on windows phone 8.1

Embed Size (px)

DESCRIPTION

Building Apps for Windows Phone 8.1 Jump Start . Videos at: http://channel9.msdn.com/Series/Building-Apps-for-Windows-Phone-8-1

Citation preview

Page 1: 23   silverlight apps on windows phone 8.1

Silverlight apps on Windows Phone 8.1

Building Apps for Windows Phone 8.1 Jump Start

Silverlight 8.1

Phone Only

Page 2: 23   silverlight apps on windows phone 8.1

In this module…

The XAML frameworks on Windows Phone 8.1Why stay on Windows Phone Silverlight?Upgrading to Silverlight 8.1Changes to the App LifecycleChanges to Tiles and Notifications

Page 3: 23   silverlight apps on windows phone 8.1

Windows Runtime

XAML Frameworks on Windows Phone 8.1

Silverlight

Page 4: 23   silverlight apps on windows phone 8.1

4

Windows Developer Platform in 8.1

Windows Runtime API Set

Graphics Audio Media

Networking File System Input

Commerce

Sensors

.NET CLRWindows Runtime (WinRT)

DirectX(C++)

Windows PhoneSilverlight(C# | VB)

Windows XAML

(C# | VB | C++)

WinJS(HTML + JS)

App Model Services

Navigation

Packaging

Contracts

Background

Store(s)

Push

Roaming

Windows Kernel

App Data Backup

Legend

Windows Phone Only

Windows OnlyWindows + Windows Phone

Page 5: 23   silverlight apps on windows phone 8.1

Windows Phone HistoryWP 7.0Silverlig

ht

WP 7.5Silverlig

ht

WP 8.0Silverlig

ht

WP 8.1Silverlig

ht

WP 8.1WinRT

W 8.0WinRT

W 8.1WinRT

Page 6: 23   silverlight apps on windows phone 8.1

• Existing Code Investment• Supporting 8.1 app and 8.0 app from a single

code base• Not yet converged

• Camera Lenses• VoIP• Lock Screen Wallpaper.• Clipboard API• Simple Sound Effects (XNA)• Run Under Lock Screen

Why stay on Windows Phone Silverlight?

We preserve your investment

Page 7: 23   silverlight apps on windows phone 8.1

Why Retarget Silverlight 8.0 app to Silverlight 8.1? Access to SD Cards Geofencing App to App SSO Share contract And much more…

Page 8: 23   silverlight apps on windows phone 8.1

9

New features available to Silverlight 8.1 appsUpgraded apps can access most of the new 8.1 WinRT APIsBackground

Tasks & Triggers

FileOpenPickerFileSavePick

er

WNS Notification

s

New Tile Templates

Action Center Management

App Data Roaming &

Backup

Credential Locker

Share Source/Targ

et

SD card r/w access

GeoFencing

Email with Attachments

SL XAML/ Direct3D

enhancements

Bluetooth LE and RFCOMM

Cryptography Web Authenticatio

n Broker

WNS Push Notification

Trigger

Storage Provider/Picker Provider

Known Folders

Appointments/Calendar

enhancements

Accessibility (UIA, Large Text, High Contrast)

Page 9: 23   silverlight apps on windows phone 8.1

• Over 90% Windows Runtime API Convergence

• Small set not of features not available in Windows XAML apps yet

ConvergencePhone Feature Only Available in Silverlight

Lenses Support

VOIP Support

Camera Capture Task

Clipboard APIs

Lock Screen Wallpaper API

Ringtone Provider / Alarm & Reminders

Simple Sound effects (XNA)

Run Under Lock Screen

Photos Extensibility

Search Extras

Page 10: 23   silverlight apps on windows phone 8.1

Retargeting your app to Silverlight 8.1

demo

Page 11: 23   silverlight apps on windows phone 8.1

12

When You Retarget To Silverlight 8.1Your app runs in the new WinRT hostThere will be platform behavior changes you’ll need to adjust your code for

Your app has access to new Windows Phone 8.1 APIsExpanded assembly reference set and WinMD

Package.appxmanifest is added to your solutionFor any modern specific app settings

You can use Silverlight background agents and WinRT background tasksOne exception is Silverlight background audio agents

Page 12: 23   silverlight apps on windows phone 8.1

Breaking Changes

Windows Runtime

Apps with XAML

C#/VB or C++

Silverlight 8.1 XAML

C#/VB

WinRTWindows Phone OS 8.1 Libraries

.NET BCL

Silverlight 8.0 XAML

C#/VB

Silverlight 8.0 execution

stack

Modern execution stack

See: Platform compatibility and breaking changes for Windows Phone Silverlight 8.1 apps in MSDN

WinRTWP 8.0

Libraries

.NET BCL

Windows Phone OS 8.1

When you retarget to Silverlight 8.1, you change the execution framework and the librariesCLR/Silverlight bug fixesAPIs may throw different/new exceptions

Documentation with full list

Page 13: 23   silverlight apps on windows phone 8.1

14

Background execution in Silverlight 8.1 apps

Silverlight 8.0

Foreground app

Periodic & Resource-Intensive Background

Agents

CBE: Run-trackers and turn-by-turn

navigation

Background AudioPlayerAgent,

AudioStreamingAgent

Silverlight 8.1

Foreground app

SL Periodic & Resource-Intensive

Background Agents

WinRT Background

Audio

WinRT Background

Tasks

CBE: Run-trackers and turn-by-turn

navigation

Background AudioPlayerAgent

, AudioStreamingA

gent

Page 14: 23   silverlight apps on windows phone 8.1

Adding new features

demo

Page 15: 23   silverlight apps on windows phone 8.1

16

App Lifecycle Changes for Silverlight 8.1

Page 16: 23   silverlight apps on windows phone 8.1

17

App behavior differences

Hitting back terminates the app just like Silverlight 8.0Different from the behavior of Windows Runtime XAML apps, which are suspendedCan force your app to use Windows Runtime app behavior by setting NavigationService.PauseOnBack to true

Silverlight 8.1 apps resume instead of replace on re-launchFast App Resume (FAR) is the *only* optionMatches Windows Runtime XAML app behavior – though ‘Back’ on first page terminates app

Page 17: 23   silverlight apps on windows phone 8.1

This is how FAR is selected in Silverlight 8.0 apps

• You have to edit the file by hand, there is no GUI for this

8.0: Enabling FAR in Properties\WMAppManifest.xml

<Tasks> <DefaultTask Name ="_default" NavigationPage="MainPage.xaml"/></Tasks>

<Tasks> <DefaultTask Name ="_default" NavigationPage="MainPage.xaml" ActivationPolicy="Resume"></Tasks>

Page 18: 23   silverlight apps on windows phone 8.1

Act

ive

Su

spen

de

d

FAR-enabled App Behavior

same

Page 19: 23   silverlight apps on windows phone 8.1

20

What do I need to do about FAR?In most cases - nothingApp templates already have ‘plumbing’ code in to make app give the same user experience on ‘Resume’ as if it is ‘Replace’Clears navigation backstackRestarts on apps ‘normal’ launch page

You may choose to change this if you want different user experience

private void InitializePhoneApplication(){ ...

// Handle reset requests for clearing the backstack RootFrame.Navigated += CheckForResetNavigation;

...}

Page 20: 23   silverlight apps on windows phone 8.1

Adding FAR handling to your Silverlight 8.1 appdemo

Page 21: 23   silverlight apps on windows phone 8.1

22

Continuing your Silverlight 8.1 app after calling a file picker

Page 22: 23   silverlight apps on windows phone 8.1

23

Contract ActivationsThe following new APIs cause the app to be activated as part of a contract:• Share contract• FileOpenPicker, FileSavePicker• WebAuthenticationBroker

Silverlight 8.1 new project templates already hook up ContractActivated event handlerAdd this to your upgraded 8.0 projects

private void InitializePhoneApplication(){ ... // Handle contract activation such as a file open or save picker PhoneApplicationService.Current.ContractActivated += Application_ContractActivated; ...}

Page 23: 23   silverlight apps on windows phone 8.1

24

Picker Contracts – Pick/Save a FileUsage Differs on Windows and Windows Phone

//Create the picker object FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;

// Users expect to have a filtered view of their folders openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".png");

// Open the picker for the user to pick a file StorageFile file = await openPicker.PickSingleFileAsync();

if (file != null) { // Do something with the file...}

Windows

//Create the picker object FileOpenPicker openPicker = new FileOpenPicker();

// Users expect to have a filtered view of their folders openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".png");

// Open the picker for the user to pick a file openPicker.ContinuationData["Operation"] = "SomeDataOrOther"; openPicker.PickSingleFileAndContinue();

Windows Phone

App suspended, may be terminated

App activated when file picked

Page 24: 23   silverlight apps on windows phone 8.1

Activation after File Picker (Silverlight 8.1)1 of 2 – App.xaml.cs sealed partial class App : Application

{

...

// Property to store the args on a File Picker activation public FileOpenPickerContinuationEventArgs FilePickerContinuationArgs { get; set; }

// Code to execute when the application is activated (brought to foreground) // This code will not execute when the application is first launched private void Application_ContractActivated(object sender, IActivatedEventArgs e) { var filePickerContinuationArgs = e as FileOpenPickerContinuationEventArgs;

//Event args is of type FileOpenPickerContinuationEventArgs so execute share target behavior if (filePickerContinuationArgs != null) { this.FilePickerContinuationArgs = filePickerContinuationArgs; } }

Page 25: 23   silverlight apps on windows phone 8.1

Activation after File Picker (Silverlight 8.1)2 of 2 – Page where picker was initiated public partial class ProfilePage : PhoneApplicationPage { ... protected override void OnNavigatedTo(NavigationEventArgs e) { var app = App.Current as App; if (app.FilePickerContinuationArgs != null) { this.ContinueFileOpenPicker(app.FilePickerContinuationArgs); } }

public async void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args) { // Same as in Windows XAML example... ... }

Page 26: 23   silverlight apps on windows phone 8.1

27

Implementing Providers in Silverlight 8.1

Silverlight 8.1 apps can also be configured to act as Providers – the app the user chooses to complete sharing, or to pick/save a fileShare TargetApp the user selects in the Share picker UI to receive content another app is ahring

FileOpenPicker or FileSavePicker ProviderApp the user selects in the Picker UI to select a file for opening/saving

Not covered in this Jump Start See MSDN documentation for details

Page 27: 23   silverlight apps on windows phone 8.1

28

Contract Activations

demo

Page 28: 23   silverlight apps on windows phone 8.1

29

Windows Notification Services on Silverlight 8.1

Page 29: 23   silverlight apps on windows phone 8.1

30

Notifications Services in Silverlight 8.1 apps

Silverlight 8.0

app

Silverlight 8.1

MPNS

app

MPNS WNS

MPNS WNS

or? ?

WNS is better!• Notifications delivered

within 5 seconds to devices connected to a network

• No more certifications to manage: WNS uses OAuth instead of SSL certification

• Convergence with Windows Store Apps

• Many improved features compared to MPNS

Page 30: 23   silverlight apps on windows phone 8.1

31

Opting into WNS

Select WNS Notification Service in WMAppManifest.xml

Page 31: 23   silverlight apps on windows phone 8.1

32

Specify Tile and Icon assets in package.appxmanifest <?xml version="1.0" encoding="utf-8"?> <Package xmlns=http://schemas.microsoft.com/appx/2010/manifest ... /> ... <Applications> <Application Id="App" Executable="AGHost.exe" EntryPoint="MainPage.xaml"> <m3:VisualElements DisplayName="TileUpdateAfterDeactivation" Square150x150Logo="Assets\SquareTile150x150.png" Square44x44Logo="Assets\Logo.png" Description="TileUpdateAfterDeactivation" ForegroundText="light" BackgroundColor="#00b2f0"> <m3:DefaultTile Square71x71Logo="Assets\SquareTile71x71.png"/> <m3:SplashScreen Image="Assets\SplashScreen.png" /> <m3:ApplicationView MinWidth="width320"/> <!--Used in XAML Designer. DO NOT REMOVE--> </m3:VisualElements>

... </Package>

Page 32: 23   silverlight apps on windows phone 8.1

33

Other considerations…

When upgrading to WNS, consider the following:• Set ToastCapable = true in your app's Package.appxmanifest file if you

raise toasts• Cycle tile not supported. Consider using the tile notification queue and a

peek template.• Flip tile not supported. Use peek tile templates or a tile notification

queue.• Make sure to use the Silverlight page-centric navigation model e.g.,

“/Page2.xaml?how=toast”• When using RequestCreateAsync() to pin a secondary tile, on

Windows Phone the app will be immediately suspended (different from Windows). You should update a pinned tile in the Deactivated event of your app.

• Make sure you have no using statements for the MPNS namespaces (Microsoft.Phone.Notification, Microsoft.Phone.Shell.*Tile* or Microsoft.Phone.Shell.ShellToast) declared anywhere in your code

Page 33: 23   silverlight apps on windows phone 8.1

34

Pinning a secondary tile using WNS APIs private async void PinAndUpdate_Click(object sender, RoutedEventArgs e) { // Create the original Square150x150 tile var tile = new SecondaryTile(SCENARIO1_TILEID, "Scenario 1", "/MainPage.xaml?scenario=Scenario1", new Uri("ms-appx:///Assets/originalTileImage.png"), TileSize.Default);

tile.VisualElements.ShowNameOnSquare150x150Logo = true; await tile.RequestCreateAsync();

// When a new tile is created, app will be deactivated and the new tile will be displayed on the start screen.

// Any code after the call to RequestCreateAsync is not guaranteed to run. // For example, updating the new secondary tile with additional data // If the app is deactivated before reaching this point, the following code will never run.

// Update the tile we created using a notification. var tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Image); ... updater.Update(notification); }

Will never run!

Page 34: 23   silverlight apps on windows phone 8.1

35

Solution: Invoke tile update code on deactivate public partial class App : Application { /// <summary> /// This delegate is invoked during Deactivate when a new tile is pinned. /// It's important to set this property before calling SecondaryTile.RequestCreateAsync() /// </summary> public static Action OnNewTilePinned { get; set; } ... private void Application_Deactivated(object sender, DeactivatedEventArgs e) { if (OnNewTilePinned != null) { OnNewTilePinned(); OnNewTilePinned = null; } }

...

Page 35: 23   silverlight apps on windows phone 8.1

36

Updating a pinned tile on deactivation

demo

Page 36: 23   silverlight apps on windows phone 8.1

App Submission

Page 37: 23   silverlight apps on windows phone 8.1

Silverlight 8.1 App Deployment

Silverlight 8.1 app runs on 8.1 Phones Only

Store supports 3 versions per app side-by-side• 8.1• 8.0• 7.1

Silverlight 8.1 apps require that you manually edit Package.appxmanifest before submission!See topic Prepare your Windows Phone Silverlight 8.1 app for publishing in MSDN documentation

Page 38: 23   silverlight apps on windows phone 8.1

Step 1: Reserve an App Name

App Name

Package Identity NamePublisher Name

Page 39: 23   silverlight apps on windows phone 8.1

Step 2: Edit AppXManifest.xml

App Name

Package Identity NamePublisher

Name

Page 40: 23   silverlight apps on windows phone 8.1

Step 3: WMAppManifest.xml

App Name

See topic Prepare your Windows Phone Silverlight 8.1 app for publishing in MSDN documentation for details

Page 41: 23   silverlight apps on windows phone 8.1

42

Summary

Page 42: 23   silverlight apps on windows phone 8.1

Which XAML Framework should you use?App Type Framework

New App WinRT or Silverlight

Existing Windows Store App WinRT

Lock Screen Image (social, weather, sports, ..)

Silverlight 8.x

Camera Based App (lenses integration) or VOIP

Silverlight 8.x

Music App Silverlight 8.0 or WinRT

Existing Silverlight Phone Apps Silverlight 8.x or WinRT

Page 43: 23   silverlight apps on windows phone 8.1

Wrap Up

Windows Runtime XAML vs Silverlight Frameworks

New WinRT APIsAdd value to your existing apps today

Protecting your investmentsNew code can be easily ported to XAMLPortable Class Libraries can now target Silverlight and XAML Apps

Page 44: 23   silverlight apps on windows phone 8.1

©2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics 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.