Windows Phone 8 の単体テスト (ベータ アプリ) 中に、電話の [キャンセル] または [戻る] ボタンを押すと、アプリ内購入ストアによってスローされる例外を検出できません。アプリは単に終了します。
MockIAP を使用してもエラーは発生しません。キャンセルまたは戻るボタンは、await receipt = Store..
. MockIAP では正しく処理されます。しかし、ユニット テストと実際のアプリ ストアでは、Cancel または Back イベントの処理が異なるようです。アプリは単純に終了します。これは、未処理のエラーがスローされているためだと思います。
私のアプリは Phonegap 2.3 で、購入部分はプラグインによって処理されます。MockIAP とは異なり、購入中に [キャンセル] または [戻る] ボタンが押されたときに、ラッパー側で何が起こっているか (つまり、ブレーク ポイントをアタッチ) がわかりません。MessageBox.Show
購入のすべてのステップを表示してみました。購入のMessageBox.Show
確認を押すとコードが機能しますが、キャンセルまたは戻るボタンを押しても機能しません。とすでに同期していEventWaitHandle
ます。
さらに、ハンドルされていないe.Handled = true
例外イベントを設定して、運が悪いとアプリを終了させないようにしました。
オンラインでは、私の購入コードはボイラープレートなので、他の人がこの問題にこれまで遭遇しなかった理由と、オンラインで解決策がない理由がわかりません。誰でもこれを修正する方法を知っていますか?
Purchase.cs (プラグイン):
private static string receipt;
private async void purchaseProduct()
{
bool canBuy = false;
try
{
li = await Store.CurrentApp.LoadListingInformationAsync();
if (li.ProductListings.ContainsKey(package_id))
{
canBuy = true;
EventWaitHandle Wait = new AutoResetEvent(false);
Deployment.Current.Dispatcher.BeginInvoke(async () =>
{
// Here is the problem.. Don't know what is passed back to receipt when Cancel or Back is pressed, which is causing the app to close during Unit Test but not MockIAP
receipt = await Store.CurrentApp.RequestProductPurchaseAsync(package_id, true);
receipt = receipt.ToString();
Wait.Set();
});
Wait.WaitOne();
}
}
catch(Exception e)
{
var eMsg = e.Message.ToString();
errorMsg("Catch Exception: ", eMsg);
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR));
}
finally
{
errorMsg("Receipt with await: ", receipt);
if (canBuy && receipt!= "")
{
errorMsg("Hitting the parsing", "");
parseXML(receipt);
prepData();
httpPostData();
Store.CurrentApp.ReportProductFulfillment(package_id);
}
else
{
errorMsg("Else Finally", "");
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR));
}
}
}
private static void errorMsg(String caption, String msg)
{
EventWaitHandle Wait = new AutoResetEvent(false);
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
MessageBox.Show(caption + msg);
Wait.Set();
});
Wait.WaitOne();
}
App.cs
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
Exception ex = (Exception)e.ExceptionObject;
EventWaitHandle Wait = new AutoResetEvent(false);
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
MessageBox.Show("Unhandled Exception: " + ex.Message);
Wait.Set();
});
Wait.WaitOne();
// Stop from exiting..
e.Handled = true;
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
//System.Diagnostics.Debugger.Break();
}
}