首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> .NET 網頁程式設計 >> 關於.NET

Windows 8 應用程式開發實戰:應用商店 API 與試用版/內購實作

     編輯:關於.NET

Windows 8 應用商店提供豐富的獲利模式:試用版、一次性購買、應用程式內購買、第三方電子商務、廣告。本實驗示範使用 Windows.ApplicationModel.Store 命名空間下的 API,配合 CurrentAppSimulator 進行開發測試。

實驗環境

  • Windows 8 + Visual Studio 2012
  • 基礎專案:Contoso Cookbook(食譜應用)
  • 授權模擬檔:Data/license.xml(含價格、試用狀態、產品定義)

練習 1:偵測試用版並顯示購買按鈕

  1. 在 App.xaml.cs OnLaunched 初始化模擬器:
var file = await Package.Current.InstalledLocation.GetFileAsync("Data\\license.xml");
await CurrentAppSimulator.ReloadSimulatorAsync(file);
  1. 建立 AppLicenseDataSource 實作 INotifyPropertyChanged,公開 IsTrial、FormattedPrice、LicenseInfo 屬性,監聽 LicenseChanged 事件更新 UI。
  2. 在關於頁面 AboutUserControl.xaml 繫結:
<TextBlock Text="{Binding LicenseInfo, Source={StaticResource License}}"/>
<Button Visibility="{Binding IsTrial, Converter={StaticResource BooleanToVisibilityConverter}}"
        Content="{Binding FormattedPrice, Source={StaticResource License}}"
        Click="OnPurchaseButtonClicked"/>

練習 2:模擬應用程式購買

private void OnPurchaseButtonClicked(object sender, RoutedEventArgs e)
{
    CurrentAppSimulator.RequestAppPurchaseAsync(false);
}
// LicenseChanged 事件會自動觸發 UI 更新,按鈕消失、顯示授權到期日

練習 3:模擬應用程式內購買(義大利食譜)

  1. 建立 ProductLicenseDataSource 封裝產品 ItalianRecipes 的授權狀態。
  2. 在 ItemDetailPage 繫結:未購買顯示購買按鈕,已購買顯示料理步驟。
  3. 點擊按鈕呼叫:
private void OnPurchaseProduct(object sender, RoutedEventArgs e)
{
    if (CurrentAppSimulator.LicenseInformation.IsTrial)
        new MessageDialog("請先升級完整版").ShowAsync();
    else
        CurrentAppSimulator.RequestProductPurchaseAsync("ItalianRecipes", false);
}

關鍵 API 對照

類別用途實機上架替換為
CurrentAppSimulator開發測試,讀取 license.xmlCurrentApp
LicenseInformation.IsTrial判斷試用版同
RequestAppPurchaseAsync購買完整應用同
RequestProductPurchaseAsync購買應用內產品同
LoadListingInformationAsync取得商店列表資訊(價格、描述)同

發布注意事項

  • 上架前將所有 CurrentAppSimulator 替換為 CurrentApp。
  • 在合作夥伴中心設定應用程式價格、試用模式、產品 ID(如 ItalianRecipes)。
  • 收益分成:開發者可獲 70%-80%(視銷售額)。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved