Windows 8.1 上市之後,我還能繼續開發 Windows 8 App 嗎?

答案是可以的! 您可以繼續使用 Visual Studio 2012 開發且上架 Win8 App,或是使用 Visual Studio 2013 開發 Win8.1 後上架;最棒的是,Visual Studio 2012 及 Visual Studio 2013 是可以同時安裝在 Windows 8.1 上的!
至於 Win8 App 及 Win8.1 App 在不同版本作業系統上之相容性如何呢? 請見下表:
image
也就是所有的 Win8 Apps,都能直接在 Win8 及 Win8.1 機器的市集中下載並且順利運行;然而 Win8.1 Apps ,則只能運行在 Win8.1 的機器上。
以這樣的角度看來,繼續開發 Win 8 App 以能同時在 Win8 及 Win8.1 的機器上運行,就會是很明智的作法,因為雖然2013/10/18起,所有的 Windows 8 就可以免費經由 Windows Store 升級為 Windows 8.1,但在這完全轉移的過程中, Win8 Apps 能同時讓最多的使用者有機會下載使用。
那是不是就沒有開發 Win8.1 Apps 的理由了呢? 有兩點考量給各位參考。
第一,就是 Win8 App 在不更改程式碼的情況,只要重新 compile 成 Win8.1 App,在效能上就會有很大進步:
image
第二,當然就是 Win8.1 加強或新增的 APIs 了。下表可以看到這些改變:
image
以上這些改變中,綜合過往一年來 Win8 App 開發合作夥伴的反應,前 3 名最有感的改變是:
1. WebView 控制項: 現在可以直接存取本地 Web 內容,甚至執行其中的 JavaScript 了! (範例: http://code.msdn.microsoft.com/XAML-WebView-control-sample-58ad63f7)
image
2. 利用全新的 RenderTargetBitmap 物件,就可以將整個 UIElement (如: Gird) 存成圖檔,以作出如 Instagram, Instaweather 等效果: (說明: http://msdn.microsoft.com/zh-tw/library/windows/apps/bg182878.aspx)
 image
3. 終於內建支援 PDF rendering,再也不用花錢購買第三方軟體套件了! (中文詳解: 在Windows 8.1 App中輕鬆完成PDF渲染)

image

小結: 在 Windows 8.1 上市之後,要開發一個 Windows Store App ,可以有以下 3 種選擇:
A. 僅作成 Win8 App: 優點是可在 Win8/8.1 機器中看到,但效能會較差且無法使用 8.1 新增 APIs.
B. 僅開發 Win8.1 App: 可使用 8.1 APIs 且在效能有進步,但無法在 Win8 機器中運行。
C. 同時開發 Win8及8.1的版本: 可使用新功能且效能好,又可同時在 Win8/8.1 機器上運行 (但增加維護成本)
未來的 Windows Store 的上傳畫面,也因這些可能的選擇而作了改變,以下是 packages 上傳畫面:
image
相同的 App 在 Win8/8.1 的資訊填寫畫面:
image
延伸閱讀: Windows 8.1 Preview:開發人員適用的新 API 和功能

摩登開發人員訓練營 – 投影片及範例程式下載及錄影

於2013/3/28-3/29 進行的摩登開發人員訓練營中,「Windows市集應用程式最佳實踐」這場次的投影片及範例程式可於 http://sdrv.ms/ZzMsuo 下載。

image

 

投影片同時可在SlideShare下載或線上觀看:

image

主題皆是以實作為主,包含以下這幾項:

•「分享」(Share Contract)

•「搜尋」(Search Contract)

•右側工具列 (Charms Bar)

•如何儲存使用者個人設定? (Roaming 應用)

•取得目前位置 (Geolocation)

•使用 WebView 的眉角

•取得及處理 JSON 資料

•其他:

–播放音樂或音效 (MediaElement)

–選取本地或需端檔案 (FilePicker)

–背景執行或下載 (Background Task/Transfer)

 

當天的課程內容錄影:

image 

關於 WebView: 10 件你需要知道的事

    Ten Things You Need to Know About WebView 是美國微軟資深工程師 Matt Small 發表的文章,我發現有幾點特別值得提出來說明,讓大家更了解 WebView 在 Windows Store App 的應用,希望對大家有幫助;其文後有他的範例程式碼供下載。
    以下是他列出的 10 點需要注意的事:
    1. WebView is not a general-purpose browser
      • WebView 這個控制項的目的,是讓你能在 App 裡,連結到某個特定的網頁,以達到此 App 所欲提供的功能;而非讓使用者能任意瀏覽任何網頁。舉例來說,如果有些特定資訊可能會時常變動 (如即時路況等),與其重新上架你的 App,將這資訊放在 WebView 當然比較適當;但如果你的 App 只是純粹作為一個入口,僅是讓使用者透過 WebView 瀏覽到某個網站首頁,再讓使用者在網站中任意點選連結的話,是非常有可能在上架審查中被退件的。
    2. WebView always renders on top of XAML
      • 這點還滿有趣的,你會發現在 XAML 中 WebView 不論放在什麼位置,程式跑起來時 WebView 一定會擋在所有的控制項之上。原因是 WebView 並非 Control object 的 subclass 的關係;原文連結裡有解法可參考。
    3. WebView doesn’t do Flash.  Or Silverlight.  Or PDF.  Or any other ActiveX control or plugin.
      • 如第1點所言, WebView 並非是一個完整的瀏覽器,為了穩定性及效能的原因並不支援 Flash, Silverlight, PDF or ActiveX,同時「目前」也不支援某些 HTML5 的功能,如 AppCache, IndexedDB, programmatic access to the Clipboard, or geolocation.
    4. How to invoke Javascript inside the displayed webpage of a Webview
      • 簡單來說 WebView 可以透過 ms-appx-web 讀取並展示已包含在你的 App 專案中的 HTML 檔案,甚至執行其中的 JavaScript 副程式。而以下的 5, 6, 8 三點都算是延伸此點的應用。
    5. How to receive information from the WebView
    6. How to inject javascript into a WebView page
    7. How to clear the WebView cache
      • 很不幸的,並無法透過程式的方式來清除 WebView cache,只能透過 command line 的方式: C:Users<username>AppDataLocalPackages<PackageName>Attrib –H –S /S /D
    8. How to embed a font into your app to be used by WebView
    9. Launching other apps from a link inside WebView
      • 如何在 WebView link 中開啟其他的 App 呢? 其實 Windows Store Apps 是沒有辦法「直接」開啟某個 App 的,但能透過 Extension handlers 的「間接」方式來開啟某特定 App,也就是設定某副檔名 (extension) 的檔案 (如:.jpeg 檔) 可以用某個 App 開啟。如以下在專案的 .appxmanifest >「宣告」>「檔案類型宣告」作設定即可:
      • image
    10. How to get rid of those annoying JavaScript exceptions when debugging
      • 在 debug 時當 WebView 瀏覽到的網頁出現 JavaScript 例外,會出現 Just-In-Time Debugger 的惱人錯誤 (如例圖),要關掉它很簡單,只要在 Visual Studio 2012 中作以下設定即可:
      • Debug > Options and Settings > Debugging > Just-In-Time > Uncheck "Script"
      • 偵錯 > 選項和設定> 偵錯 > Just-In-Tim > 取消勾選「指令碼」
      • image
        其實以上大部份的內容在 WebView 的 MSDN 官方文件的 Remakrs 段落中都有說明,只是可能沒有很細節的描述,在此也一併轉貼如下給大家參考:
        Remarks
        WebView is not a Control subclass and thus does not have a control template. The display area is the Width and Height.
        WebView has the characteristic that other UI regions such as controls cannot be rendered on top of the WebView. This is because of how window regions are handled internally, particularly how input events are processed and how the screen draws. If you want to render HTML content and also place other UI elements on top of that HTML content, you should use WebViewBrush as the render area. The WebView still provides the HTML source information, and you reference that WebView through the SourceName property. WebViewBrush does not have this overlay limitation.
        If you want to display an interactive WebView that only occasionally has overlapping content (such as a drop-down list or app bar), you can temporarily hide the WebView control when necessary, replacing it with an element using a WebViewBrush fill. Then, when the overlapping content is no longer present, you can display the original WebView again. For more info, see the WebView control sample.
        WebView doesn’t support many of the UIElement events like KeyDown, KeyUp, and PointerPressed. A common workaround to this problem is to use WebView.InvokeScript with eval to use the HTML event handlers, and to use window.external.notify from the HTML event handler to notify the application using WebView.ScriptNotify.
        Note WebView always uses Internet Explorer 10 in document mode. Additionally, WebView does not currently support some HTML5 features including AppCache, IndexedDB, programmatic access to the Clipboard, or geolocation. Furthermore, WebView does not support the ms-appdata scheme, although it does support the ms-appx-web scheme. This enables you to load content files in your project.