32
Windows Phone 8 Tips & Tricks for Developers Sascha Corti, Microsoft Switzerland Technical Evangelist [email protected] | techpreacher.corti.com | @techpreacher #shape1 3

Windows Phone 8 Tips & Tricks for Developers

  • Upload
    pennie

  • View
    34

  • Download
    0

Embed Size (px)

DESCRIPTION

Windows Phone 8 Tips & Tricks for Developers. Sascha Corti, Microsoft Switzerland Technical Evangelist [email protected] | techpreacher.corti.com | @ techpreacher. #shape13. Agenda. Updating Apps from WP 7.1 to WP 8 App Localization The Multilingual App Toolkit Proximity: NFC - PowerPoint PPT Presentation

Citation preview

Page 1: Windows Phone 8 Tips  & Tricks for Developers

Windows Phone 8Tips & Tricks for DevelopersSascha Corti, Microsoft SwitzerlandTechnical [email protected] | techpreacher.corti.com | @techpreacher

#shape13

Page 2: Windows Phone 8 Tips  & Tricks for Developers

Agenda

AgendaUpdating Apps from WP 7.1 to WP 8App LocalizationThe Multilingual App Toolkit

Proximity: NFCMaps and LocationRunning in the BackgroundFast App Resume done right!

Next Session: Apps Targeting Win8 & WP8

Page 3: Windows Phone 8 Tips  & Tricks for Developers

Updating your Apps from WP7.1 to WP8

Page 4: Windows Phone 8 Tips  & Tricks for Developers

Compile in the CloudMoving to CoreCLR brings Native Image Generator (NGEN)Expensive and Time consuming on Device.

Compile in the cloud NGEN’s your Code when you submitCode in XAP is NGEN’d and XAP updated with Compiled Code.

What about existing Apps?7.5 apps are NGEN’d so Windows Phone 8 gets Compiled Version.Original 7.5 apps is kept for Download to 7.5 Devices

Windows Phone 7.5Marketplace

Windows Phone 8Marketplace

Page 5: Windows Phone 8 Tips  & Tricks for Developers

WP 7.1 and 8 Apps in the Store

PitfallsVersion Number of the WP 8 XAP must be higher than WP 7.1 XAP.Updating WP 7.1 XAP with WP 8 XAP Removes WP 7.1 Support.

“My App” Store ListingOS 7.1 OS 8.0

XAP-3WXGA

XAP-1 XAP-2WVGA

In App Products

XAP-4720p

OS 7.1 Metadata

OS 8.0Metadata

Page 6: Windows Phone 8 Tips  & Tricks for Developers

WP 7.1 and 8 Apps in the Store

Page 7: Windows Phone 8 Tips  & Tricks for Developers

Two Top Level Projects Duplicate WP7.1 Project in Solution.

Rename to “xyz WP7” and “xyz WP8”.

Update WP8 Project.

2 Separate Code Bases.

Page 8: Windows Phone 8 Tips  & Tricks for Developers

Linked Source Code Files Remove Classes / UI from WP8 Solution.

Add Existing Files from WP7 as Link.

Don’t link App.xaml(.cs), WMAppManifest.xml

2 Separate Code Baseswith shared Files.

Page 9: Windows Phone 8 Tips  & Tricks for Developers

Compile-Time Adaptation Define Custom Compilation Symbol for WP8 Project

Use Compiler Directives to distinguish

Does not exist for XAML

#if WP8 // Code to run in WP8#else // Code to run in WP7#endif

Page 10: Windows Phone 8 Tips  & Tricks for Developers

Async Pattern in WP7.1 App Add NuGet Package: “Microsoft.Bcl.Async”.

Include Prerelease Packages in Search.

Page 11: Windows Phone 8 Tips  & Tricks for Developers

demoMaintaining both WP7 and WP8 Projects.

Page 12: Windows Phone 8 Tips  & Tricks for Developers

Shared Assemblies Add Portable Class Library to Solution Reference from both ProjectsVery useful in MVVM based Projects.

Portable Class Library

ViewModelBusiness Logic

WP7.1 ProjectView

WP8 ProjectView

Page 13: Windows Phone 8 Tips  & Tricks for Developers

Two Branches Of Same App Project Create Branch off

WP7 Project

Keep both Branches, Merge WP8 Changes Selectively to keep updating WP7 Project

Page 14: Windows Phone 8 Tips  & Tricks for Developers

App LocalizationMultilingual App Toolkit for Visual Studio 2012

Page 15: Windows Phone 8 Tips  & Tricks for Developers

Multilingual App Toolkit for VS 2012Free Downloadhttp://corti.ch/vs2012-mat

Multilingual EditorWorks with XLIFF Format FilesCan use Bing TranslationState per Resource & Language for Teams

LinksHow to use the Multilingual App Toolkit

Page 16: Windows Phone 8 Tips  & Tricks for Developers

Testing Multilingual AppsMultiple Emulator ImagesDifferent Language/Locale SettingsDark/Light Color Themes

Settings not Persisted

Page 17: Windows Phone 8 Tips  & Tricks for Developers

demoMultilingual Apps

Page 18: Windows Phone 8 Tips  & Tricks for Developers

Proximity: NFCAnd some Bluetooth

Page 19: Windows Phone 8 Tips  & Tricks for Developers

Near Field CommunicationsProvides Connectivity Between Devices that are very close together (within 3-4 Centimeters)Between Devices and unpowered NFC Chips

Transfer of a Message or Byte StreamMax Data Transfer Rate 424 kbits/s. Typical Data Transfer Rates from 30 kbits/s to 60 kbits/s

NFC can be used to initiate a connection implemented using Bluetooth or WiFiExtends the PeerFinder to allow an application to set up a StreamSocket between two devicesThe ID_CAP_PROXIMITY capability must be enabled for the application

Page 20: Windows Phone 8 Tips  & Tricks for Developers

Near Field Communications OptionsApp to App

Tag to App

App to Device

Page 21: Windows Phone 8 Tips  & Tricks for Developers

Listening for Incoming NFC MessagesProximityDevice device = ProximityDevice.GetDefault(); // Register Event Handlers for NFC Detection / Departuredevice.DeviceArrived += device_DeviceArrived;device.DeviceDeparted += device_DeviceDeparted; // Register Event Handlers for Various Incoming NFC Message Formatsdevice.SubscribeForMessage("WriteableTag", WriteableTagHandler);device.SubscribeForMessage("Windows.MySubType", SubTypeHandler);device.SubscribeForMessage("WindowsUri", WindowsUriHandler);device.SubscribeForMessage("WindowsMime", WindowsMimeHandler);device.SubscribeForMessage("NDEF", NDEFHandler);

//Writable Size Tag receivedprivate void WriteableTagHandler(ProximityDevice sender, ProximityMessage message){ var WritableSize = System.BitConverter.ToInt32(message.Data.ToArray(), 0); Dispatcher.BeginInvoke(() => { TagSize.Text = WritableSize.ToString() + " Bytes"; });}

Page 22: Windows Phone 8 Tips  & Tricks for Developers

Publishing NFC Messages//create a NDEF messagevar ndefRecord = new NdefTextRecord{ Text = NfcMessage.Text, LanguageCode = CultureInfo.CurrentCulture.TwoLetterISOLanguageName};var ndefMessage = new NdefMessage { ndefRecord }; //publish binary NDEF message.long publishId = device.PublishBinaryMessage("NDEF:WriteTag", ndefMessage.ToByteArray().AsBuffer(), publishHandler);

private void publishHandler(ProximityDevice sender, long messageId){ // Tag has been written to. Stop publishing. device.StopPublishingMessage(publishId); publishId = null;}

http://ndef.codeplex.com/

Page 23: Windows Phone 8 Tips  & Tricks for Developers

Prox

imity

Ta

pper

http://proximitytapper.codeplex.com/

Select Emulator(s)

Tap virtual NFC

Send Message(s)

Page 24: Windows Phone 8 Tips  & Tricks for Developers

demoSending Data via NFC from an App

Page 25: Windows Phone 8 Tips  & Tricks for Developers

Maps and LocationAnd their ability to run in the Background!

Page 26: Windows Phone 8 Tips  & Tricks for Developers

Multitasking Background LocationNokia Map TechnologyGlobal NAVTEQ Map dataOffline map support, Turn-by-Turn Directions

For DevelopersAllow for Location Apps to continue running in the BackgroundNew Nokia Map Control (Bing Maps control supported but deprecated)Converge with Windows 8 / Managed and Native Code

Windows Phone Map ServicesGeocoding: Latitude,Longitude to AddressReverse Geocoding: Address to Latitude,LongitudeRouting: RouteQuery, Route, RouteLeg, RouteManeuver Four Cartographic Map Modes

Page 27: Windows Phone 8 Tips  & Tricks for Developers

Built-In Map TasksMapTaskLaunch Map App.Can specify Center, Point to show, Zoom Level etc.

MapsDirectionTaskStart Turn-by-Turn Directions.Missing Parameters substituted by user’s Location.

MapsDownloaderTaskDownload Map Data for Offline Use.

Page 28: Windows Phone 8 Tips  & Tricks for Developers

Single Location Request

Locaction Tracking Tracking In Background

public async Task<Geocoordinate> GetSinglePositionAsync(){ Geolocator geolocator = new Geolocator();  geolocator.DesiredAccuracyInMeters = 10; Geoposition geoposition = await geolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1),

TimeSpan.FromSeconds(30)); return geoposition.Coordinate;}

void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args){ Dispatcher.BeginInvoke(() => { txtLat.Text = args.Position.Coordinate.Latitude.ToString("0.00"); txtLon.Text = args.Position.Coordinate.Longitude.ToString("0.00"); });}

WMAppManifest.xml

<DefaultTask Name="_default" NavigationPage="SearchPage.xaml"> <BackgroundExecution> <ExecutionType Name="LocationTracking"/> </BackgroundExecution></DefaultTask>Actively listen for location change

eventsAttach/Detach Event Handler to Start/Stop

Page 29: Windows Phone 8 Tips  & Tricks for Developers

App has access toLocation, SensorsAudio / SpeechNetwork, StorageShellToast and ShellTile.Update

Users canClose the Running AppDisable BG Functionality per App

App runs in Background untilApp stops tracking LocationAnother Location Tracking App moves to BackgroundUser disables Location Services4 hours without bringing the App to the ForegroundBattery Saver ON / Low memory

Background Execution: Resources

CPU allocation capped at

10%

Page 30: Windows Phone 8 Tips  & Tricks for Developers

demoBuilding a Map App with Background Location Tracking

Page 31: Windows Phone 8 Tips  & Tricks for Developers

Developer ResourcesStreamed sessions from //build/ conferencehttp://channel9.msdn.com/Events/Build/2012

New Phone Developer Centerhttps://dev.windowsphone.com/en-us/dashboard

All about Windows Phonehttp://www.windowsphone.com

Windows Phone Developer Learninghttp://msdn.microsoft.com/en-us/library/windowsphone/develop

Windows Phone 8 SDK free Downloadhttp://dev.windowsphone.com

Page 32: Windows Phone 8 Tips  & Tricks for Developers

© 2013 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.