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
Windows Phone 8Tips & Tricks for DevelopersSascha Corti, Microsoft SwitzerlandTechnical [email protected] | techpreacher.corti.com | @techpreacher
#shape13
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
Updating your Apps from WP7.1 to WP8
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
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
WP 7.1 and 8 Apps in the Store
Two Top Level Projects Duplicate WP7.1 Project in Solution.
Rename to “xyz WP7” and “xyz WP8”.
Update WP8 Project.
2 Separate Code Bases.
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.
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
Async Pattern in WP7.1 App Add NuGet Package: “Microsoft.Bcl.Async”.
Include Prerelease Packages in Search.
demoMaintaining both WP7 and WP8 Projects.
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
Two Branches Of Same App Project Create Branch off
WP7 Project
Keep both Branches, Merge WP8 Changes Selectively to keep updating WP7 Project
App LocalizationMultilingual App Toolkit for Visual Studio 2012
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
Testing Multilingual AppsMultiple Emulator ImagesDifferent Language/Locale SettingsDark/Light Color Themes
Settings not Persisted
demoMultilingual Apps
Proximity: NFCAnd some Bluetooth
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
Near Field Communications OptionsApp to App
Tag to App
App to Device
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"; });}
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/
Prox
imity
Ta
pper
http://proximitytapper.codeplex.com/
Select Emulator(s)
Tap virtual NFC
Send Message(s)
demoSending Data via NFC from an App
Maps and LocationAnd their ability to run in the Background!
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
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.
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
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%
demoBuilding a Map App with Background Location Tracking
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
© 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.