Search Unity

iOS purchase dialog box pop again on UserCancelled. Anyone met this problem before?

Discussion in 'Unity IAP' started by tangyinglin0228, Apr 18, 2020.

  1. tangyinglin0228

    tangyinglin0228

    Joined:
    Apr 23, 2018
    Posts:
    16
    I printed the log and the button and other functions in the class were called once. I almost follow what the tutorial does. I tried to search on google but it seems that I am the only one who have this problem. May be I missed something or did something wrong? And the document did tell what I could do in OnPurchaseFailed(). The parameters it offers don't seem to do anything.
    Or is it a normal behavior? I am using 2019.3.1f1. Any input is appreciated. Thank you.

    Code (CSharp):
    1. public class Purchaser : MonoBehaviour, IStoreListener
    2. {
    3.  
    4.     public static IStoreController m_StoreController;
    5.     public static IExtensionProvider m_StoreExtensionProvider;
    6.  
    7.  
    8. private void Awake()
    9.     {
    10.    
    11.         var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    12.         builder.AddProduct(kProductIDNonConsumable, ProductType.NonConsumable);
    13.         UnityPurchasing.Initialize(this, builder);
    14.       }
    15.  
    16. public void InitializePurchasing()
    17.     {
    18.      
    19.         if (IsInitialized())
    20.         {
    21.        
    22.             return;
    23.         }
    24.         var builder =ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    25.         builder.AddProduct(kProductIDNonConsumable, ProductType.NonConsumable);
    26.         UnityPurchasing.Initialize(this, builder);
    27.      
    28.     }
    29.  
    30. public bool IsInitialized()
    31.     {
    32.         Product product =m_StoreController.products.WithID(kProductIDNonConsumable);
    33.  
    34.         if (product != null && product.availableToPurchase)
    35.         {
    36.          
    37.             m_StoreController.InitiatePurchase(product);
    38.  
    39.         }
    40.             return m_StoreController != null && m_StoreExtensionProvider != null;
    41.     }
    42.  
    43. public void BuyNonConsumable()
    44.     {
    45.       //OnClick calls this function
    46.        BuyProductID(kProductIDNonConsumable);
    47.    
    48.        
    49.     }
    50. public void BuyProductID(string productId)
    51.     {
    52.  
    53.         if (IsInitialized())
    54.             {
    55.                 Product product = m_StoreController.products.WithID(productId);
    56.  
    57.                 if (product != null && product.availableToPurchase)
    58.                 {
    59.                  
    60.                     m_StoreController.InitiatePurchase(product);
    61.                 }
    62.                 else
    63.                 {
    64.                     Debug.Log("Product not found or not available for purchase!");
    65.                 }
    66.             }
    67.             else
    68.             {
    69.                 Debug.Log("Not able to initialize the purchase.");
    70.             }
    71.         }
    72.  
    73. public void OnPurchaseFailed(Product i, PurchaseFailureReason p)
    74.     {
    75.         Debug.Log("Purchase failed " + p);
    76.         if(p == PurchaseFailureReason.UserCancelled)
    77.         {
    78.             //I don't know what I can do to stop it from calling the dialog box again here!
    79.         }
    80.     }
    81. public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    82.     {
    83.    
    84.         m_StoreController = controller;
    85.         m_StoreExtensionProvider = extensions;
    86.         Product product = m_StoreController.products.WithID(kProductIDNonConsumable);
    87.  
    88.         if (product != null && product.availableToPurchase)
    89.         {
    90.                //I cache the order information to local storage here.
    91.  
    92.         }
    93.     }
    94. }
     
  2. tangyinglin0228

    tangyinglin0228

    Joined:
    Apr 23, 2018
    Posts:
    16
    And here is the Xcode log between 2 Cancel taps. Sorry it's an AR app that I have to test it on physical devices.

    Purchase failed UserCancelled

    Purchaser:OnPurchaseFailed(Product, PurchaseFailureReason)

    UnityEngine.Purchasing.JSONStore:OnPurchaseFailed(PurchaseFailureDescription, String)

    System.Action:Invoke()

    UnityEngine.Purchasing.Extension.UnityUtil:Update()


    (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)


    -> applicationWillResignActive()

    2020-04-18 16:56:49.155451+0100 helloworldar[25948:6164156] [Process] kill() returned unexpected error 1

    2020-04-18 16:56:49.155862+0100 helloworldar[25948:6164156] [Process] kill() returned unexpected error 1

    2020-04-18 16:56:49.156196+0100 helloworldar[25948:6164156] [Process] kill() returned unexpected error 1

    2020-04-18 16:56:49.156716+0100 helloworldar[25948:6164156] [Process] kill() returned unexpected error 1

    2020-04-18 16:56:49.156788+0100 helloworldar[25948:6164156] [Process] kill() returned unexpected error 1

    2020-04-18 16:56:49.202135+0100 helloworldar[25948:6164156] [Process] kill() returned unexpected error 1

    2020-04-18 16:56:49.202228+0100 helloworldar[25948:6164156] [Process] kill() returned unexpected error 1

    2020-04-18 16:56:49.206324+0100 helloworldar[25948:6164156] [Process] kill() returned unexpected error 1

    2020-04-18 16:56:49.206739+0100 helloworldar[25948:6164156] [Process] kill() returned unexpected error 1

    2020-04-18 16:56:49.334475+0100 helloworldar[25948:6164156] Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service

    2020-04-18 16:56:49.336556+0100 helloworldar[25948:6164156] Could not signal service com.apple.WebKit.Networking: 113: Could not find specified service

    2020-04-18 16:56:50.807424+0100 helloworldar[25948:6164156] [Process] kill() returned unexpected error 1

    2020-04-18 16:56:50.807736+0100 helloworldar[25948:6164156] [Process] kill() returned unexpected error 1

    2020-04-18 16:56:50.894903+0100 helloworldar[25948:6164156] [Process] kill() returned unexpected error 1

    2020-04-18 16:56:50.895046+0100 helloworldar[25948:6164156] [Process] kill() returned unexpected error 1

    2020-04-18 16:56:50.895140+0100 helloworldar[25948:6164156] UnityIAP: UpdatedTransactions

    2020-04-18 16:56:50.895220+0100 helloworldar[25948:6164156] UnityIAP: PurchaseFailed: 2

    -> applicationDidBecomeActive()

    2020-04-18 16:56:51.233611+0100 helloworldar[25948:6164156] [Process] kill() returned unexpected error 1

    2020-04-18 16:56:51.234731+0100 helloworldar[25948:6164156] [Process] kill() returned unexpected error 1

    2020-04-18 16:56:51.235045+0100 helloworldar[25948:6164156] [Process] kill() returned unexpected error 1

    2020-04-18 16:56:51.235896+0100 helloworldar[25948:6164156] [Process] kill() returned unexpected error 1

    onPurchaseFailedEvent({0}): helloworldar.premium

    UnityEngine.Purchasing.PurchasingManager:OnPurchaseFailed(PurchaseFailureDescription)

    UnityEngine.Purchasing.JSONStore:OnPurchaseFailed(PurchaseFailureDescription, String)

    System.Action:Invoke()

    UnityEngine.Purchasing.Extension.UnityUtil:Update()


    (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)


    Purchase failed UserCancelled
     
  3. tangyinglin0228

    tangyinglin0228

    Joined:
    Apr 23, 2018
    Posts:
    16
    Update: It looks like that it's an iOS problem. After updating my iPhone7 to 13.4.1. The bug just went away.
     
    SamOYUnity3D likes this.