Unity IAP not initializing

╄→尐↘猪︶ㄣ 提交于 2019-11-30 19:46:10

I think that you would already solve the issue. If not I am going to share some screenshots of how I did it on the Apple Developer page:

1- Upload an app to testflight (upload an app to the console using XCode or application loader) - This step is already completed.

2- Go to Features

and add as many items as you want. I believe that you have items here with "submit for revision" status. As you can see I have it approved and working in my unity project.

3- The IAP items should be active for testing after 24h (for your testflight approved users). To add users you have to go to Apple Developer Console and edit the roles in there for the provisioning profile.

4- If you did all that (which I believe you did); the only thing that is left is the XCode side. However, I am going to recommend you to add your IAP script in the scene as an empty object to make sure that it is initialized and you give it enough time to set everything properly.

5- XCODE: To add IAP functionality you need to set the proper permissions in your provisioning profile and add the capabilities

.

6 - Further help with the team provisioning: provides with some useful help. Apple IAP Documentation -> Xcode will update your certificate if you check the IAP function.

Anyway, I had the same issue as you are having, my Google IAP was working but my iOS build was failing the purchase process. My final advise is to review all the code/settings/certificates and wait 24h to be sure that Apple applied the changes to your app.

Let us know please.

Thanks.

I was receiving "Received 0 products" until I filled in Contact Info, Bank Info and Tax Info. I was so mad I couldn't make it work for more then 2 month.

So, in your code, there's a call to Start() that calls InitializePurchasing() which then sets up the ConfigurationBuilder and ultimately calls:

UnityPurchasing.Initialize(this, builder);

I think you're setting up the builder with things that you don't need, specifically the GooglePlay product IDs. E.g. from your InitializePurchasing() method:

// Add a product to sell / restore by way of its identifier, associating the general identifier with its store-specific identifiers.
builder.AddProduct(kProductIDConsumable, ProductType.Consumable, new IDs(){{ kProductNameAppleConsumable, AppleAppStore.Name },{ kProductNameGooglePlayConsumable,  GooglePlay.Name },});// Continue adding the non-consumable product.
builder.AddProduct(kProductIDConsumable2, ProductType.Consumable, new IDs(){{ kProductNameAppleConsumable2, AppleAppStore.Name },{ kProductNameGooglePlayConsumable,  GooglePlay.Name },});// Continue adding the non-consumable product.
builder.AddProduct(kProductIDConsumable3, ProductType.Consumable, new IDs(){{ kProductNameAppleConsumable3, AppleAppStore.Name },{ kProductNameGooglePlayConsumable,  GooglePlay.Name },});// Continue adding the non-consumable product.
builder.AddProduct(kProductIDConsumable4, ProductType.Consumable, new IDs(){{ kProductNameAppleConsumable4, AppleAppStore.Name },{ kProductNameGooglePlayConsumable,  GooglePlay.Name },});// Continue adding the non-consumable product.
UnityPurchasing.Initialize(this, builder);

I would start by calling AddProduct with just the details for a single store (the iOS App Store). *(I'd also remove all the code that you don't need, the additional consumable products, as it's just clogging up your code with things you don't need, making it harder to work out what's going on)_.

For example, from one of the Unity 3d pages:

using UnityEngine;
using UnityEngine.Purchasing;

public class MyStoreClass : MonoBehaviour, IStoreListener {
    void Start() {
        ConfigurationBuilder builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
        builder.AddProduct("levelpackfoo", ProductType.NonConsumable, new IDs() { "levelpackfoo", AppleAppStore.Name });
        UnityPurchasing.Initialize(this,builder);
    }
    public void OnInitialized(IStoreController controller, IExtensionProvider extensions) {}
    public void OnInitializeFailed(InitializationFailureReason error) {}
    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e) { return PurchaseProcessingResult.Complete; }
    public void OnPurchaseFailed(Product item, PurchaseFailureReason r) {}
}

In that example code, the've got the ConfigurationBuilder being created, added-to, and initialised all in the Start() method...

Even before doing that, however, you should be able to find out the result of your call to: UnityPurchasing.Initialize(this, builder);...

I would do this because, the failure you're getting is:

"BuyProductID FAIL. Not initialized."

So, we know that the call to if (IsInitialized()) in void BuyProductID(string productId) is returning false, leading to:

else
{
    // ... report the fact Purchasing has not succeeded initializing yet. Consider waiting longer or retrying initiailization.
    Debug.Log("BuyProductID FAIL. Not initialized.");
}

And here's the IsInitialized() method:

private bool IsInitialized()
{
    // Only say we are initialized if both the Purchasing references are set.
    return m_StoreController != null && m_StoreExtensionProvider != null;
}

So, one of m_StoreController or m_StoreExtensionProvider is null... Now let's look at the two IStoreListener callbacks:

//  
// --- IStoreListener
//

public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
    // Purchasing has succeeded initializing. Collect our Purchasing references.
    Debug.Log("OnInitialized: PASS");

    // Overall Purchasing system, configured with products for this application.
    m_StoreController = controller;
    // Store specific subsystem, for accessing device-specific store features.
    m_StoreExtensionProvider = extensions;
}

public void OnInitializeFailed(InitializationFailureReason error)
{
    // Purchasing set-up has not succeeded. Check error for reason. Consider sharing this reason with the user.
    Debug.Log("OnInitializeFailed InitializationFailureReason:" + error);
}

Check your debug logs (or put a breakpoint in each of those methods)... after the earlier call to UnityPurchasing.Initialize(this, builder); - which are you getting?

  • OnInitialized?
  • OnInitializeFailed?

You need to know if you're getting OnInitialized success and therefore initialising m_StoreController and m_StoreController.

Update 1

Not sure if you've consulted these pages from the Unity docs; the first has a walkthrough of the IAP setup for iTunesConnect and your Xcode project and the second provides additional info:

I suppose you created an IAP product on Itune connect and product Id is matched between code and itune connect and bundle Id is correct:

Maybe you hasn't select the Team in project setting. You'll also need to create a sandbox tester account and log out real appstore account on testing device for fully test IAP

Since this was my first IOS in app purchase setup the item blocking me was filling out the tax and bank info. Once that was done I was able to test with a sandbox account.

I have same problem. After that I try to apply it on "itunes connect" on the contract for paid applications (contact info, tax info, bank info) try this direct link https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/da/jumpTo?page=contracts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!