2016-01-05 29 views
0

我無法在發佈模式下運行我的UWP應用程序,因爲當我試圖訪問CurrentApp.LicenseInformation時,它總是立即崩潰。UWP應用程序發佈模式CurrentApp錯誤

enter image description here 重現步驟: 創建一個新的空白UWP應用程序。轉到MainPage.xaml.cs並添加以下內容:

public sealed partial class MainPage : Page 
{ 
    public MainPage() 
    { 
     this.InitializeComponent(); 
     Loaded += MainPage_Loaded; 
    } 

    private void MainPage_Loaded(object sender, RoutedEventArgs e) 
    {    
     ProductIapTextBlock.Text = CurrentApp.LicenseInformation.ProductLicenses[ "hello" ].IsActive.ToString(); 
    } 
} 

現在更改爲發佈模式和x86平臺並嘗試運行該應用程序。它應該與上面的圖像中的錯誤一起崩潰。

這裏有什麼問題?問題隱藏在我的代碼中,還是UWP中存在問題?

+0

看看這個:http://stackoverflow.com/questions/34364580/wp8-1-and-wp10-differences – Gusman

+0

看到了,但它並沒有幫助。這是一個非常簡單和基本的場景,不是一個Windows Phone 8.1應用程序。這就是爲什麼它更大的問題。 –

+0

但是您是否檢查過您的Window Store帳戶以查看是否全部填入了? – Gusman

回答

1

根據此文件:https://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.store.licenseinformation.aspx

的應用程序需要在商店發佈的CurrentApp.LicenseInformation查詢工作。因此,開發唯一的選項是使用模擬器版本,然後在準備好上傳到商店時更改代碼。

如果您的代碼與模擬許可證檢查一起工作,它應該在現場商店中工作。但是,我正計劃將我的應用發佈爲隱藏在商店中(即僅可從直接鏈接獲得,不可搜索)以進行測試。然後,如果它正常工作,我會正確地發佈到商店。

+0

當我將代碼從'CurrentAppSimulator'更改爲'CurrentApp'時,它沒有隻會在我的個人電腦上崩潰,而且在認證過程中也會崩潰。我如何解決這個問題?很明顯,該應用程序尚未發佈在這一點上,但我也不能使用'CurrentAppSimulator',因爲獲得認證的軟件包最終也會在Store中... – jonhue

0

使用compilation directives,在代碼的第一行定義指令。

#define DUMMY_STORE 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using Windows.ApplicationModel.Store; 

namespace SO 
{ 
    public class LicenseManager 
    { 
     private readonly Dictionary<string, bool> _dummyLicense; 

#if DUMMY_STORE 
     public LicenseManager() 
     { 
      // Init license for testing only 
      _dummyLicense = new Dictionary<string, bool> 
      { 
       {"hello", true} 
      }; 
     } 
#endif 

     public bool IsActive(string feature) 
     { 
#if DUMMY_STORE 
      return _dummyLicense[feature]; 
#else 
      return CurrentApp.LicenseInformation.ProductLicenses[feature].IsActive; 
#endif 
     } 
    } 
} 

這種替換代碼:

private void MainPage_Loaded(object sender, RoutedEventArgs e) 
{    
    ProductIapTextBlock.Text = new LicenseManager.IsActive("hello").ToString(); 
} 

而且不要忘記評論#define DUMMY_STORE你把它上傳到商店之前。

+0

我知道這是可以調試的,但是發佈模式應該在上傳到Store之前表現得很好(至少在這種情況下是這樣) –

相關問題