windows phone 7.5 tips and tricks for developers sascha p. corti developer evangelist, microsoft...
TRANSCRIPT
Windows Phone 7.5Tips and Tricks for Developers
Sascha P. CortiDeveloper Evangelist, Microsoft [email protected] | techpreacher.corti.com | @techpreacher
Windows Phone7.5
Software Architecture
App Model
Cloud and Integration
Services
Hardware Foundation
UI Model
Gyro
Camera, Sensors & Motion
Fast App Switch
Silverlight and XNA
Integration
Silverlight 4.0
Flexible chassis
SQL CEGen GC
Push, Alerts
Multitasking
Calendar Contacts
Maps
Extras, Tiles
Sockets
Multitasking
Background AudioUse AudioPlayerAgentShows controls on Lock Screen.
Background Notification SvcAlarmsReminders (Snooze & Launch into App Parameterized)
Run under Lock Screen (ie. GPS Apps)Set the PhoneApplicationService.ApplicationIdleDetectionMode Property.Mind the Power Consumption - See Certification Requirements 6.3 (http://corti.ch/wp7appcert)
Background File Transfers
Background Transfer Service
download
My WP Book App
Ready Player One
Jpod
WP7 for Devs
Great Mysteries o
CloudBackground
Transfer Service < 100
MB
<20 MB
<~3.0 MB
GET
POST
void DownloadWithBTS(Uri sourceUri, Uri destinationPath){ btr = new BackgroundTransferRequest(sourceUri, destinationUri); btr.TransferStatusChanged += BtsStatusChanged; btr.TransferProgressChanged += BtsProgressChanged; BackgroundTransferService.Add(btr);}
void BtsProgressChanged(object sender, BackgroundTransferEventArgs e){
DrawProgressBar(e.Request.BytesReceived);
}
using Microsoft.Phone.BackgroundTransfer;
void GetCurrentProgress(){ DrawProgressBar(btr.BytesReceived);}
completed
My WPBook App
ISO Store
AgentsPeriodicOn IdleMay have One or Both
Initialized in Foreground, Run in BackgroundPersisted across Reboots
User control through Control PanelUp to a Maximum of 18 periodic agents
Synchronize with Foreground through Mutex
Agent runs for up to 14 Days (can be renewed)
Occurrence: Every 30 minDuration: 15 secondsScenarios: Incremental Data Sync
Occurrence: External power, non-cell networkDuration: 10 minutesScenarios: Data Feasting
Background Agents
Accessing the Camera
PhotoCamera ClassNew API developed for WP
Silverlight WebCam APIPorted from SL4 Desktop with added functionality
Silverlight 4 WebCam
Reuse SL4 WebCam Knowledge
Easily Target Desktop and Phone
Record Video and Audio into File
PhotoCamera
Take High Quality Photos
Handle Hardware Button
Handle Flash mode and Focus
Build custom Camera
App
Build Augmented Reality App
(with MotionSensor)
Display in your App:
VideoBrush
AR Overla
ys
Custom
Camera
Hardware Sensors & API
HardwareAccelerometer Always available
Compass Not Mandatory in HW (but present if Gyro is)
Gyro Not Mandatory in HW
APIsMotionSensor All the Sensor + Math Use whenever available Also works w/o Gyro
Individual APIs available for all Sensors
Motion
Sensor
[cosγ .cos
α −cosβ . sin
α+sinβ . sin
γ .cosα sin β .
sin α+cos β
.sin γ.cos α
cos γ .sin α
cos β.cos α
+sin β. sin γ
. sinα− sin
β .cosα+cos β
. sin γ.sin α
− sinγ
sin β .cosγ
cos β.sin γ
]
Local Database
App Data Folder
App Root Folder
Install
DBDatabaseFile (r/o)
Creates root folder
sandboxed to App
Package
Manager
AppCreates/Managesfiles and settings
WP7 Isolated Storage
APIs
Application
Settings File
ApplicationFiles
DB
Database file
// Define the data context.public partial class WineDataContext : DataContext {
public Table<Wine> Wines;public Table<Vineyard> Vineyards;public WineDataContext(string connection) : base(connection) { }
}
// Define the tables in the database[Table]public class Wine{
[Column(IsPrimaryKey=true]public string WineID { get; set; }[Column]public string Name { get; set; }……
}
// Create the database form data context, using a connection stringDataContext db = new WineDataContext("isostore:/wineDB.sdf");if (!db.DatabaseExists()) db.CreateDatabase();
Multiple Live Tiles
Local Tile APIsFull Control of ALL Properties
Multiple Tiles per appCreate, Update / Delete / QueryLaunches directly to In App URI
Back of Tile UpdatesFull Control of all Properties when your App is in Foreground or BackgroundContent, Title, BackgroundFlips from Front to Back at random IntervalSmart Logic make Flips Asynchronous
Title
Content Title Background
Content string is bigger
Learning all about WP 7.5 Development
Getting Started Location and Sensors
Fundamental Concepts Media
Common Application Development Tasks Push Notifications and Tiles
Application Features XNA-Specific Code Samples
Background File Transfers, Agents, and Alarms Windows Phone Development Quick Starts
Cameras and Photos Windows Phone Training Kit
Controls Developing a Windows Phone Application from Start to Finish
A Case Study for Building Advanced Windows Phone Applications
http://corti.ch/wp7codesamples
Tango Explained
Lower Cost Devices for Growth Markets23 more markets Bahrain, Bulgaria, China, Costa Rica, Croatia, Estonia, Iceland,
Iraq, Israel, Kazakhstan, Latvia, Lithuania, Qatar, Romania, Saudi Arabia, Slovakia, Slovenia, Thailand, Turkey, UAE, Ukraine, Venezuela and Vietnam
6 Times the Number of Pre-Loaded Apps
Changed Memory and Processor RequirementsAccommodate 7x27 processors and 256 MB of memory.No Background Agents allowed to run. Nokia Lumia 610
Platform Fragmentation Incoming?Transparent to Developers95% of Today’s Apps will work.Developers can define if their App is available on Tango Devices.
Aaah!Fragmentat
ion!
♥
Test Tango Today
Install the Windows Phone 7.1.1 SDK UpdateDownload link: http://corti.ch/wp-sdk-711 Make sure your App performs OK in Low Memory
Add the 23 New Markets!Edit existing App Listings in App Hub account at http://create.msdn.com
2 phone emulators
256 & 512 MB Memory
Tango Best Practices
Optimize Startup TimeMinimize Code in App/Page Constructors and Keep Launching/OnNavigatedTo Activity MinimalLeverage the system tray ProgressIndicator for the best performance.Once first Frame is rendered, keep blocking Calls off of the UI Thread.Adding a splash screen can additionally improve startup time: this frame is drawn by the OS itself
Reduce Memory UsagePer certification requirement 5.2.5: Max 90MB of App Memory usage on 256MB Devices.Use the memory profiler and memory-related APIs to profile your app’s memory usage.Leverage the new back stack manipulation APIs exposed in Windows Phone 7.5
Handle Feature ReductionsOn 256MB devices, Background Agents (PeriodicTasks/ResourceIntensiveTasks) are disabled.This is surfaced to the App via an InvalidOperationException which all Apps must handle.
Microsoft Blog Post
Nokia Best Practice Tips
New Application Resume UX
Faster user experience! Enabled for all WP7.5 apps Recompile & Test your
WP7 application
Resuming . . .
WindowsPhone 7
WindowsPhone 7.5
TapTap and
hold
running
deactivated
dormant
activated
Phone resources detachedThreads & timers suspended
Fast App Resume
Save App
State!
State isPreserved
Tombstoned
OnNavigatedFromApplication_Deactiva
ted10
Tombstoned
Application_Activated
OnNavigatedTo
Tombstoned
Application_Launching
OnNavigatedTo
Resuming . . .
running
deactivated
dormant
activated
Tombstone the
oldest app
tombstoned
Restore App State
RestoreState !
Tombstoned
Application_Activated
OnNavigatedTo
Deactivation Resource ManagementDeactivated App
PhoneApplicationPage.OnNavigatedFrom
PhoneApplicationService.Deactivated
Framework:Detach Resources
Framework:Suspend Timers and Threads
Dormant App
MediaPlayer.PauseMediaElement.Pause
SoundEffectInstance.PauseVibrateController.StopPhotoCamera.Dispose
Save Page / Global StateXNA Audio Paused
Sensors Notifications suppressed
Networking Cancelled
Sockets Disconnected
MediaElement Disconnected
Camera Disposed
Activation Resource Management
MediaElement.Source/Position/PlaySocket.ConnectAsync
new PhotoCamera/VideoCamera
Restore app state if tombstoned
Running App
PhoneApplicationPage.OnNavigatedTo
PhoneApplicationService.Activated
Framework:Attach Resources
Framework:Resume Timers and Threads
Dormant App
XNA Audio Resumed
Sensors Notifications resumed
Networking Completed with Cancellation
Sockets -
MediaElement -
Camera -
Developing for Multiple WP VersionsKeep Versions of your App for WP7, WP7.5, etc. Copy WP7 solution Add Existing Files as Linked Assets Use Conditional Compilation
Adding In App Advertising to Windows Phone Apps
3Publish to Store
Set Ad Unit/App IDs in your AppSubmit Ad-enabled App to StoreTrack your success at PubCenter
1 Download Ad
SDK
Download Ad SDKAdd few lines of code to add AdsSupport for Silverlight & XNA
2 Register App
Sign in to PubCenterRegister your app at PubCenterGenerate App ID and Ad Unit IDs
pubCenter under the Hood
Ads available for Region
US, UK, ESP, IT, DENOT Switzerland
Control Language
10 for Developers22 for End Users
Developer Registration & Pay
19 CountriesIncluding Switzerland
€
Microsoft Advertising Links
Main SitesMonetize your Windows Phone 7 AppspubCenter
White PapersFrequently Asked QuestionsMonetization Best Practices
DownloadsMicrosoft Advertising SDK for Windows PhoneMSDN Documentation: Advertising SDK for Windows PhoneAdvertising SDK for Windows Phone AdControl (Silverlight) Sample Advertising SDK for Windows Phone XNA Sample
Advertising Resources
Doing GPS the Right Way
Requirements for CertificationExplicitly ask for Permission on First RunCreate a Settings Page that Lets the User switch GPS On/Off Contains a Disclaimer that says
What you use the GPS for What happens to the Data in case it’s sent to a Server
Best PracticeTurn Off and Dispose of GeoCoordinateWatcher if you don’t need it!
Marketplace: New RegionsResubmit your App to reach New Markets!No more ITIN needed on W8-BENMarketplace Website with Deep Linking
Windows Phone 7: 16
Windows Phone 7.5 +19 (35)
Added in 2012: +28 (63)Bahrain, Bulgaria, China, Costa Rica, Croatia, Estonia, Iceland, Iraq, Israel, Kazakhstan, Latvia, Lithuania, Qatar, Romania, Saudi Arabia, Slovakia, Slovenia, Thailand, Turkey, UAE, Ukraine, Venezuela, Vietnam, Argentina, Indonesia, Malaysia, Peru, Philippines
Marketplace: Distribution Options
* People who obtain deep link can access and download.
“Beta” Private Public# of users 100 unlimited unlimited
App Price Must be “free” Can be “paid” Can be “paid”
Time Limited Expires after 90d No No
Updateable No Yes Yes
Certification Required No Yes Yes
Discoverable No No * Yes
Access Control Limited to test user WLIDs provided
No No
Target Users Beta Users Private Users Public Users
Online Resources I : The BasicsApp Hub http://create.msdn.com
Tools http://wpdev.ms/wpsdk71rc
WP on MSDN Library http://wpdev.ms/wponmsdn
WP “How To” Index http://wpdev.ms/wphowtos
WP UX Guide http://wpdev.ms/wpuxguide
WP P&P Guide http://wpdev.ms/wppnpguide
WP Dev Blog http://wpdev.ms/developerblog
Porting to WP http://wpdev.ms/porting
WP Labs (WP7) http://wpdev.ms/wprtmhols
WP Labs (WP7.5) http://wpdev.ms/mangohol
WP SL Quick Starts http://wpdev.ms/xamlquick
Online Resources II : Videos
WP Jumpstart http://wpdev.ms/jumpstarts
WP How To Videos http://wpdev.ms/howvidsWP “Absolute Beginners” http://wpdev.ms/beginvidsInside WP on C9 http://wpdev.ms/insidewpDesign Toolbox http://wpdev.ms/designtbWP Game Dev Vids http://wpdev.ms/gamevidsWP at MIX 11 Vids http://wpdev.ms/wpmix11WP at TENA 11 Vids http://wpdev.ms/wptena11
Online Resources III : Other
App Hub FAQ http://wpdev.ms/apphubfaq
App Hub Forums http://wpdev.ms/ahforumRegistration Walkthrough http://wpdev.ms/regwalkSubmission Walkthrough http://wpdev.ms/subwalkCert Requirements http://wpdev.ms/certreqWP Samples on MSDN http://wpdev.ms/officialsamplesSL Toolkit for WP http://wpdev.ms/wpsltkAzure Toolkit for WP http://wpdev.ms/wpwaztk
Online Resources IV : 3rd PartySilverlight Show on WP http://www.silverlightshow.net/Search.asp
x?q=%5Bwindows-phone-7%5D
Windows Phone Geek http://www.windowsphonegeek.com/WPDEV on Twitter http://twitter.com/#search?q=wp7devWPDEV on REDDIT http://www.reddit.com/r/wp7devWPDEV on Stack Overflow http://stackoverflow.com/questions/tagge
d/windows-phone-7
© 2012 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.
© 2012 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.