Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background
-
Upload
dan-ardelean -
Category
Technology
-
view
356 -
download
0
description
Transcript of Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background
WPReborn 2013
Dan [email protected]@live.com
Live App: tile, notifiche, lock screen e servizi in background
@dnlombardia#wpreborn
1. Live Tiles 2. Lock screen notifications3. Lock screen background4. Background Agents5. Background Transfers
Agenda
1. Live Tiles
Windows Phone 7.5Tile NotificationsPrimary, secondary, front and back
Toast Notifications
Live Tiles• Collegamenti alla nostra applicazione• Si possono creare Tile secondarie• Per Windows Phone 7.8 e 8 abbiamo:
1. 3 dimensioni2. 3 template
Templates1. Flip
2. Iconic
3. Cycle
Flip Tile Template (TemplateFlip, FlipTileData)
medium: 336x336
small: 99x99
wide: 691x336
Cycle Tile (TemplateCycle, CycleTileData)
medium: 336x336
small: 99x99
wide center crops to medium
wide: 691x336
Iconic Tile Template (TemplateIconic, IconicTileData)
medium: 202x202small: 110x110
white with transparency only
crop tight on horizontal
Aggiornare le Live Tiles
• Possono essere aggiornate usando notifiche PUSH
• Direttamente dalla applicazione (WP7.5 Mango)• In modo schedulato (WP8)
API Front Count Front Title Front Image Back Content
Back Title Back Image
Multi Tile
Push Yes Yes Yes Yes Yes Yes Yes
ShellTile Yes Yes Partial Yes Yes Partial Yes
ShellTileSchedule
No No Yes No No No Yes
API Front Count Front Title Front Image Back Content
Back Title Back Image
Multi Tile
Push Yes Yes Yes Yes Yes Yes Yes
ShellTile Yes Yes Partial Yes Yes Partial Yes
ShellTileSchedule
Yes Yes Yes Yes Yes Yes Yes
API Front Count Front Title Front Image Back Content
Back Title Back Image
Multi Tile
Push Yes Yes Yes Yes Yes Yes Yes
ShellTile Yes Yes Yes Yes Yes Yes Yes
ShellTileSchedule
Yes Yes Yes Yes Yes Yes Yes
API Front Count Front Title Front Image Back Content Back Title Back Image
Multi Tile XML
Push Yes Yes Yes Yes Yes Yes Yes Yes
ShellTile Yes Yes Yes Yes Yes Yes Yes Yes
ShellTileSchedule
Yes Yes Yes Yes Yes Yes Yes Yes
API per aggiornare le Live Tiles
Focus su coerenzaShellTileSchedule aggiorna tutte le proprietàShellTile accetta web URIs per immaginiBONUS: Tutte le classi ShellTileData accettano stringhe XML
Aggiornamento Live Tiles da XAML
Aggiornamento usando Tile Schedule
• Ricorrenza: Onetime, EveryHour, EveryDay, EveryWeek o EveryMonth
• Dimensioni immagini <150KB (era 80KB per WP 7.5)
• Tempo di download non deve superare 45 secondi
• Se va in eccezione troppe volte il SO cancella la schedulazione
Live TilesDemo
Live Tiles WP 7.8 e 8.0 per progetti 7.11. Reflection http://ow.ly/hanGP
WMAppManifest.xml<AppExtra xmlns="" AppPlatformVersion="8.0">
<Extra Name="Tiles"/> </AppExtra>
private static Version TargetedVersion = new Version(7, 10, 8858);public static bool IsTargetedVersion {get{return Environment.OSVersion.Version >= TargetedVersion;}}
Live Tiles WP 7.8 e 8.0 per progetti 7.12. Codeplex MangoPollohttp://mangopollo.codeplex.com/
MangoPolloDemo
2. Lock screen notifications
Lock screen1. L’utente può selezionare le
applicazioni abilitate ad interagire con la Lock Screen
2. Un massimo di 5 applicazioni abbilitate per notifiche di tipo icon
3. Bisogna:1. Fornire l’icona per le notifiche2. Registrare le varie Extension
Come aggiornare Icon Count e Text1. Lock Screen Icon Count e Text sono i valori della tile primaria
• Le tile secondary non sono usate
2. Le informazioni vengono visualizzate solo se I campi sono valorizzati
• Count solo se la Tile principale ha Count
3. La Tile primaria non deve necessariamente essere presente sulla Start Screen
4. Aggiornamento usando:• Local Shell Tiles API• Push Notifications
Lock screen notificationsDemo
3. Lock screen background
Lock Screen Background per Windows Phone 8
Aggiungere Lock Screen Background Extension
WMAppManifest.xml
<Extension ExtensionName="LockScreen_Background" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F" TaskID="_default" />
Impostare l’immagine di sfondo
• Asset fornito con l’applicazione usare ms-appx:///
Uri imageUri = new Uri("ms-appx:///background1.png", UriKind.RelativeOrAbsolute); LockScreen.SetImageUri(imageUri);
• Per Local Folder usare ms-appdata:///local/
Uri imageUri = new Uri("ms-appdata:///local/background2.png", UriKind.RelativeOrAbsolute); LockScreen.SetImageUri(imageUri);
Lock ScreenDemo
4. Background Agents
New updates
from Background
Agent
Background Agents• Una applicazione Windows Phone può creare
un “background agent”1. PeriodicTask, ResourceIntensiveTask o entrambi nello stesso tempo2. Solo un agent per applicazione
• Il agent può essere eseguito quando l’applicazione non é in esecuzione
• Il agent non equivale ad una applicazione che gira in background
Background agents
SI
• Tiles• Toast• Location• Network• R/W ISO store• Sockets
NO
• Display UI• XNA libraries• Microphone and camera• Sensors• Play audio(may only use background audio APIs)
PeriodicTasks• Il PeriodicTask viene eseguito ogni tanto
– Di solito ogni 30 minuti ma dipende da quello che il telefono sta eseguendo ad un certo momento
• Usato per attività veloci e ripetitive– Eseguito per un massimo di 25 secondi– Utilizzo di memoria<= 6 MB– Viene cancellato dopo 2 crash consecutivi– Esiste un limite per il numero massimo di agent che sono attivi ad un certo
momento
• Da usare per location tracking, polling background services, tile updates
ResourceIntensive TasksViene eseguito solo in certe condizioni:• Il telefono è in carica• La carica della batteria è >90%• Il telefono è collegato via WiFi• Il telefono non viene usato (Lock screen)
Viene eseguito per un Massimo di 10 minuti– Utilizzo di memoria<= 6 MB– Viene cancellato dopo 2 crash consecutivi
Come creare un Background Agent
Il codice di un Background Agent
namespace LocationLogTaskAgent{ public class ScheduledAgent : ScheduledTaskAgent { protected override void OnInvoke(ScheduledTask task) { //TODO: Add code to perform your task in background NotifyComplete(); } }}
Concurrent Data Access
public bool LoadLogFromIsolatedStorageFile(){ mut.WaitOne(); // Wait until it is safe to enter
try { // read the file here return true; } catch { LogText = ""; return false; } finally { mut.ReleaseMutex(); // Release the Mutex. }}
Schedulazione di un Background AgentPeriodicTask t;
t = ScheduledActionService.Find(taskName) as PeriodicTask;bool found = (t != null);if (!found) { t = new PeriodicTask(taskName);}t.Description = description;t.ExpirationTime = DateTime.Now.AddDays(10);if (!found){ ScheduledActionService.Add(t);} else{ ScheduledActionService.Remove(taskName); ScheduledActionService.Add(t);}
Debugging Background Agents
#if DEBUG_AGENT ScheduledActionService.LaunchForTest(taskName, TimeSpan.FromSeconds(60));#endif
Consigli Background AgentsRinnovate spesso• Meglio ogni volta ce l’applicazione viene lanciata
Non implementare funzionalità critica• L’utente può disabilitare il agent• Il agent potrebbe essere sospeso da SO per batteria scarica
Per funzionalità critiche considerate Push Notifications
Background AgentsDemo
Novità Windows Phone 8Il background agent non viene sospeso dopo 2 settimane se:
1. L’applicazione ha Tiles sulla Start Screen• e l’agent chiama ShellTile.Update da PeriodicTask
2. L’applicazione usa Lock Screen• Count o detailed status (anche senza Tile sulla Start Screen)
• Background image provider quando chiama SetImageUri
5. Background Transfers
Background Transfers
• Background task per trasferimento files da Isolated storage• Funzionano anche quando l’applicazione non è in primo piano• Possibilità di monitorare lo stato• Collegamenti HTTP e HTTPS
– FTP non funziona per il momento
• Il sistema mantiene una coda degli trasferimenti attivi
Background Transfers Policies• Dimensioni
» Upload : 5Mb» Download usando dati cellulare: 20Mb» Download usando WiFi: 100Mb
• Impostate le condizioni desiderate usando TransferPreferences
• Numero Massimo di Background transfers per applicazione: 25 » Erano 5 per Windows Phone OS 7.1
WPReborn 2013
Dan [email protected]@neologics.eu
___________________________________________________Live App: tile, notifiche, lock screen e servizi in background
@dnlombardia#wpreborn