41
初探 WINDOWS 市集 APP 開發 劉耀群 (Ouch Liu) Ouch@點部落 Ouch1978

初探 Windows 市集 App 開發

Embed Size (px)

Citation preview

Page 1: 初探 Windows 市集 App 開發

初探 WINDOWS 市集 APP 開發

劉耀群 (Ouch Liu)

Ouch@點部落

Ouch1978

Page 2: 初探 Windows 市集 App 開發

大綱

Windows Phone Silverlight Apps 的改變

動態磚、背景工作與多工

資料儲存、雲端同步與備份

Page 3: 初探 Windows 市集 App 開發

在我們開始之前…

Page 4: 初探 Windows 市集 App 開發

你的開發工具更新了嗎?

Visual Studio 2013 Update 3

bit.ly/1AntwB0

Page 5: 初探 Windows 市集 App 開發

你的WP8.1模擬器更新了嗎?

Windows Phone 8.1 Update 1 模擬器

bit.ly/1kIMNt0

Page 6: 初探 Windows 市集 App 開發

WINDOWS PHONE SILVERLIGHT APPS 的改變

Page 7: 初探 Windows 市集 App 開發

WINDOWS PHONE 的 XAML 框架

Page 8: 初探 Windows 市集 App 開發

WINDOWS PHONE 的 XAML 框架

以前,透過 Visual Studio 2012 建立 Windows Phone 專案時…

Page 9: 初探 Windows 市集 App 開發

WINDOWS PHONE 的 XAML 框架

現在,透過 Visual Studio 2013 建立 Windows Phone 專案時…

Page 10: 初探 Windows 市集 App 開發

WINDOWS PHONE 的 XAML 框架

XAML SilverlightWP

Silverlight 8.0

WinRT APIs

XAML 8.1

WinRT APIs

WP Silverlight

8.1

WinRT APIs

Page 11: 初探 Windows 市集 App 開發

SILVERLIGHT 8.1

涵蓋了將近 90% 的 WinRT APISilverlight 獨佔功能:

鏡頭支援 (Lenses Support)

VOIP支援 (VOIP Support)

相機拍照工作 (Camera Capture Task)

剪貼簿相關API (Clipboard APIs)

鎖定畫面桌面API (Lock Screen Wallpaper API)

鈴聲/鬧鐘/提醒音效 (Ringtone Provider / Alarm & Reminders)

簡單音效 (Simple Sound effects - XNA)

鎖定畫面下執行 (Run Under Lock Screen)

相片擴充功能 (Photos Extensibility)

搜尋附加功能 (Search Extras)

Page 12: 初探 Windows 市集 App 開發

SILVERLIGHT 8.1 的新功能

Storage SD Card Data Enhancements (Data.XML)

Device Discovery (Devices.Enumeration) Graphics Enhancements D2D/Dwrite (Win32)

Streams (Input/Output/RandomAccess…) Sensors (Accelerometer, Light, compass, gyro, magnet, orientation,…)

Media Editing (MediaStreamSource, MediaProperties) Email with Attachments

Media Transcoding Data: Backup/Restore

Graphics Enhancements WIC Data: Roaming

Share Source Networking (HTTP, Connectivity, ...)

Share Target (Provider) Audio Effects

RFComm Media Capture

App 2 App Single Sign On Bluetooth 4.0 (Low Energy)

Background Tasks Web Authentication

Password Credentials Storage Enhancements (FileIO, PathIO, AccessCache, Compression)

WNS Push Notification Trigger Social RTWNS Notifications (Badge/Tile/Toast/Notification Center) Storage (Picker Provider, Provider)

InputPane MSA (Windows.Security.Authentication.OnlineId )

GeoFencing AtomPub, Http, Syndication (Windows.Web)

NFC Secure Payment Media Foundations (win32)

Known Folders (Audio/Video/Photos/…) Advertising ID

Appointments/Calendar API enhancements Accessibility (UIA, Large Text, High Contrast)

Appointments/Calendar brokered UI Precise Caret Placement - No APIs

Background Transfer

Page 13: 初探 Windows 市集 App 開發

升級到 SILVERLIGHT 8.1

以 Siverlight 8.0 開發的 App 仍然可以在 Windows Phone

8.1 裝置上執行

Binary 100% 相容

由 Silverlight 8.0 升級到 Silverlight 8.1 -> 可能會失敗

原始碼不一定 100% 相容

Page 14: 初探 Windows 市集 App 開發

SILVERLIGHT 8.1 改了什麼?

CLR / Silverlight Bug 修正

App 行為調整

Fast App Resume (FAR) 預設為開啟

按下 Back 鈕會和 8.0 一樣把 App 終止掉

Page 15: 初探 Windows 市集 App 開發

升級到 SILVERLIGHT 8.1 之後...

測試、測試、測試!!

就算程式碼看起來無痛轉換,也可以順利開啟,但並不代表執行

過程中不會踩到隱藏的地雷。

你的 App 有使用到背景工作嗎?

Silverlight 8.1不再支援背景持續執行工作,而且所能佔用的

CPU時間也降低了。

確保 App 支援各種不同的解析度

ScreenResolution 設定在 Silverlight 8.1 中已經被移除了。

Page 16: 初探 Windows 市集 App 開發

升級到 SILVERLIGHT 8.1 之後... (續)

Application Bar 的尺寸不再是固定值了。

Application Bar 的大小將會隨著裝置的解析度而有所差異。

Silverlight 8.1 不再支援透過 XNA 繪製的功能

如果要在 App 中檢查記憶體使用量?

可以透過

Windows.System.MemoryManager.AppMemoryUsage 屬性

來取得記憶體使用量。

Page 17: 初探 Windows 市集 App 開發

還有什麼要注意的呢?

Platform compatibility and breaking changes for

Windows Phone Silverlight 8.1 apps

bit.ly/1qgsEXx

Page 18: 初探 Windows 市集 App 開發

與 WINDOWS 8 一致的分享功能

透過 ShareContract / ShareTarget實作分享功能:

At installation, registers as ShareTarget through manifest declaration

Share Target AppShare BrokerSource App

Page 19: 初探 Windows 市集 App 開發

與 WINDOWS 8 一致的分享功能

透過 ShareContract / ShareTarget實作分享功能

DEMO

Page 20: 初探 Windows 市集 App 開發

已經實作了 ShareTarget 的 App 不應該再去呼叫

ShareStatusTask、ShareLinkTask 與 ShareMediaTask 三個

API 的相關功能,否則可能會造成 App 閃退。

實作 SHARETARGET 的注意事項

Page 21: 初探 Windows 市集 App 開發

動態磚、背景工作與多工

Page 22: 初探 Windows 市集 App 開發

WP 8.0 的動態磚

Flip Iconic Cycle

Page 23: 初探 Windows 市集 App 開發

WP 8.1 的動態磚

Page 24: 初探 Windows 市集 App 開發

WP 8.1 的動態磚樣版

基本上,Windows Phone 8.1 可用的動態磚樣版和 Windows 8.1

可用的動態磚樣版是大致相同的,但是:

Windows Phone 8.1 不支援 310 x 310 的動態磚。

有部份的樣版為 Windows Phone 8.1 獨佔,Windows 8.1 並不支

援。

Windows Phone 允許您使用各種樣版,但是基於可顯示尺寸的關

係,某些樣版或是部份內容可能會無法顯示。

Page 25: 初探 Windows 市集 App 開發

WP 8.1 的動態磚樣版列表

詳細的動態磚樣版列表,請上:

bit.ly/1mTqyMh

Page 26: 初探 Windows 市集 App 開發

建立基本的動態磚

DEMO

Page 27: 初探 Windows 市集 App 開發

更新動態磚

DEMO

Page 28: 初探 Windows 市集 App 開發

WP 8.1 的多工模式

一旦 App 不再顯示在畫面上,它就會進入暫停狀態。

App 進入暫停狀態後,還是可以透過下列方式提供訊息:

動態磚 或 通知訊息

排程通知 與 提醒

作業系統提供的各種工作

背景工作 及 代理程式

Page 29: 初探 Windows 市集 App 開發

WP 8.1 常見的背景工作分類

排程性工作 (Scheduled Task)

PeriodicTask、ResourceIntensiveTask

背景傳輸服務 (Background Transfer Service)

背景定位 (Background Location Tracking)

VOIP和聲音代理 (VOIP and Audio Agents)

Page 30: 初探 Windows 市集 App 開發

WP 8.1 的背景工作運作方式

每個背景工作都會由另一個程序所承載。

每個工作可以擁有一個觸發器,而一個觸發器則可以擁有多個觸發

狀態。

App 必需要向使用者取得授權才得以執行背景工作。

背景工作所能使用的資源仍然是受限的。

Page 31: 初探 Windows 市集 App 開發

透過背景工作發送通知

DEMO

Page 32: 初探 Windows 市集 App 開發

透過背景工作建立動態磚圖片

DEMO

Page 33: 初探 Windows 市集 App 開發

資料儲存、雲端同步與備份

Page 34: 初探 Windows 市集 App 開發

開發 APP 時常常遇到的問題

存取不同的儲存區需要使用不同的 API

使用者資料儲存區的存取權是受限的

建立跨裝置的一致體驗是很困難的一件事

有價值的資料被困在舊裝置裡

Page 35: 初探 Windows 市集 App 開發

STORAGEFILE 與 STORAGEFOLDER

可以透過下列類型的動作來存取大部份的檔案內容:

Local files/folders

File activation

Media libraries

Share contract

Pickers

不同的檔案類型可以取出不同的 metadata

幾乎所有的 WinRT API 都可以支援

Page 36: 初探 Windows 市集 App 開發

APP DATA MODEL

Roaming

Folder

• 資料會在不同的Windows 設備間漫游

• 主要的本地端儲存空間 • 暫時的儲存空間• 當空間不足時會被清除

• 不會被備份• 不會被清除• 只有手機支援

Settings

Local

Folder Settings

Local Cache

Folder Settings

Temp

Folder

Page 37: 初探 Windows 市集 App 開發

存取使用者的檔案

DEMO

Page 38: 初探 Windows 市集 App 開發

ROAMING

Phone App – PFN 12345

Roaming Local Temp

Windows App – PFN 12345

RoamingLocalTemp

PFN 12345

Roaming

App 透過標準的檔案/設定 API 寫入資料

同步引擎會依照Trigger (使用者閒置、電力、網路等等因素)週期性的傳送資料

OneDrive 允許每個 App 最多可以儲存 100kb 的資料 (不包含在使用者的資料容量限額內),如果達到限額,則同步會自動停止。

其他客戶端被通知該透過WNS更新資料。如果App正在執行中,則會引發事件。

LocalCache

Page 39: 初探 Windows 市集 App 開發

ROAMING

DEMO

Page 40: 初探 Windows 市集 App 開發

ROAMING BEST PRACTICES

Use roaming for settings and small state

Stick to core WinRT types

Avoid dependencies across files/settings

Be resilient against sync delays

“High priority” settings are not recognized on the phone

Use Windows.Security.Credentials for secure data

Page 41: 初探 Windows 市集 App 開發

Q & A

發問 & 贈獎時間