2017-03-06 97 views
0

我使用適用於iOS的Xamarin.InAppPurchases插件。基本上,如果用戶沒有登錄到iTunes,對InAppPurchaseManager.RestorePreviousPurchases的調用不會觸發登錄提示。我看着反彙編,看到它基本上正在運行一些檢查,然後調用內部恢復購買。我修改了我的代碼。有誰知道調用RestoreCompletedTransactions帶和不帶字符串名稱標識符的含義嗎?當這樣調用時,會出現提示。在iOS上使用Xamarin.InAppPurchases恢復購買

//Forced to call this in order to trigger login 
SKPaymentQueue.DefaultQueue.RestoreCompletedTransactions(); 

//Redundant, but I don't know the implications of removing it 
inAppPurchaseManager.RestorePreviousPurchases();    

湯姆格蘭維爾的頂端評論似乎表明他有同樣的問題。 https://components.xamarin.com/view/xamarin.inapppurchase

編輯 - 我相信這是Xamarin中的一個錯誤。我在這裏發佈了這個bug:Bugzilla 53100我提出了一個解決方法,它涉及到調用收據API。它似乎適用於所有情況。

回答

0

以下是我爲解決該問題而採取的解決方法。

//Forced to call this in order to trigger login 
//Get a receipt 
var receiptRequest = new SKReceiptRefreshRequest(); 
receiptRequest.Init(); 
receiptRequest.Delegate = new ReceiptRequestDelegate(inAppManager); 
receiptRequest.Start(); 

//Use this to trigger login 
public class ReceiptRequestDelegate : SKRequestDelegate 
{ 
    private InAppPurchaseManager inAppManager; 

    public ReceiptRequestDelegate(InAppPurchaseManager iapm) 
    { 
     inAppManager = iapm; 
    } 

    public override void RequestFinished(SKRequest request) 
    { 
     //Now call restore purchases 
     inAppManager.RestorePreviousPurchases(); 
    } 

    public override void RequestFailed(SKRequest request, NSError error) 
    { 
     //Handle request failed 
    } 
} 

至於我有關調用RestoreCompletedTransactions有和沒有applicationUsername的影響問題,似乎會​​影響到一些在你可以在服務器上存儲事務的信息。它可以讓你用他們的本地用戶名識別用戶,因爲在iTunes中它只會將它與他們的iTunes帳戶相關聯。你可以在這裏瞭解更多Detecting Irregular Activity