Search Unity

[Closed] IAP not working on iOS but works on Android

Discussion in 'Unity IAP' started by Blobfish, Feb 9, 2017.

Thread Status:
Not open for further replies.
  1. Blobfish

    Blobfish

    Joined:
    Feb 28, 2013
    Posts:
    30
    Hello,

    I'm struggling to get IAP to work on iOS, it works in the editor and on the Android version but on iOS it's not showing the dialogue or any sign of life.

    Code (CSharp):
    1.  
    2. public class IAPManager : MonoBehaviour, IStoreListener
    3. {
    4.     private static IStoreController m_StoreController;        
    5.     private static IExtensionProvider m_StoreExtensionProvider;
    6.    
    7.     public static string kProductIDNonConsumable = "ad_removal";
    8.  
    9.     void Start()
    10.     {
    11.         if (m_StoreController == null)
    12.         {
    13.             InitializePurchasing();
    14.         }
    15.     }
    16.  
    17.     public void InitializePurchasing()
    18.     {
    19.         if (IsInitialized())
    20.         {
    21.             return;
    22.         }
    23.        
    24.         var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    25.         builder.AddProduct(kProductIDNonConsumable, ProductType.NonConsumable);
    26.         UnityPurchasing.Initialize(this, builder);
    27.     }
    28.  
    29.  
    30.     private bool IsInitialized()
    31.     {
    32.         return m_StoreController != null && m_StoreExtensionProvider != null;
    33.     }
    34.  
    35.     public void BuyNonConsumable()
    36.     {
    37.         BuyProductID(kProductIDNonConsumable);
    38.     }
    39.  
    40.     void BuyProductID(string productId)
    41.     {
    42.         if (IsInitialized())
    43.         {
    44.             Product product = m_StoreController.products.WithID(productId); if (product != null && product.availableToPurchase)
    45.             {
    46.                 Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
    47.                 m_StoreController.InitiatePurchase(product);
    48.             }
    49.             else
    50.             {
    51.                 Debug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
    52.             }
    53.         }
    54.         else
    55.         {
    56.             Debug.Log("BuyProductID FAIL. Not initialized.");
    57.         }
    58.     }
    59.  
    60.     public void RestorePurchases()
    61.     {
    62.         if (!IsInitialized())
    63.         {
    64.             Debug.Log("RestorePurchases FAIL. Not initialized.");
    65.             return;
    66.         }
    67.        
    68.         if (Application.platform == RuntimePlatform.IPhonePlayer ||
    69.             Application.platform == RuntimePlatform.OSXPlayer)
    70.         {
    71.             Debug.Log("RestorePurchases started ...");
    72.             var apple = m_StoreExtensionProvider.GetExtension<IAppleExtensions>();
    73.             apple.RestoreTransactions((result) => {
    74.                 Debug.Log("RestorePurchases continuing: " + result + ". If no further messages, no purchases available to restore.");
    75.             });
    76.         }
    77.         else
    78.         {
    79.             Debug.Log("RestorePurchases FAIL. Not supported on this platform. Current = " + Application.platform);
    80.         }
    81.     }
    82.  
    83.  
    84.     public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    85.     {
    86.         Debug.Log("OnInitialized: PASS");
    87.         m_StoreController = controller;
    88.         m_StoreExtensionProvider = extensions;
    89.     }
    90.  
    91.  
    92.     public void OnInitializeFailed(InitializationFailureReason error)
    93.     {
    94.         Debug.Log("OnInitializeFailed InitializationFailureReason:" + error);
    95.     }
    96.  
    97.  
    98.     public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    99.     {
    100.         if (String.Equals(args.purchasedProduct.definition.id, kProductIDNonConsumable, StringComparison.Ordinal))
    101.         {
    102.             Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));
    103.             PlayerPrefs.SetInt("ads", 0);
    104.         }  else
    105.         {
    106.             Debug.Log(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", args.purchasedProduct.definition.id));
    107.         }
    108.         return PurchaseProcessingResult.Complete;
    109.     }
    110.  
    111.  
    112.     public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
    113.     {
    114.         Debug.Log(string.Format("OnPurchaseFailed: FAIL. Product: '{0}', PurchaseFailureReason: {1}", product.definition.storeSpecificId, failureReason));
    115.     }
    116. }
    117.  
    This is called when you press a button:
    Code (CSharp):
    1. IAPManager iap = GetComponent<IAPManager>();
    2.                         if (iap != null)
    3.                             iap.BuyNonConsumable();
    I've added the IAP to itunes connect as shown:


    My unity version is 5.5.1f1 and the purchasing script is version 1.9.3.
     
  2. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
  3. kuailaiwanli

    kuailaiwanli

    Joined:
    Apr 22, 2013
    Posts:
    47
    Lot of people meet this problem,me too.
    everything is set correctly,but xcode always say:Unavailable product
    I've sign out apple store account to test.
    But I can't login with tester account,always say tester apple id can't use in itunes store!
    So I leave the account empty.

    When run in xcode,click "buy" button,xcode say unavailable product,IAP initialize faied!
    There's no dialogue coming out in ios, but android has.
    Is it unity's bug?
    I'm confused by this problem for 4 days!There's no solution on web
     
  4. Rhiojin

    Rhiojin

    Joined:
    Dec 12, 2012
    Posts:
    8

    I solved this problem for iOS by setting up a paid contract on Itunesconnect, located in the Agreements, Tax and Banking section. All my IAPS worked within 30mins after finalising contact info, bank info and tax info in the same section.
     
Thread Status:
Not open for further replies.