IAP not working in XCode

Hi, I am trying to implement Unity IAP in my project, but every time I try to purchase a product my app crashes?!?

Here is the error in XCode
[85973-skærmbillede-2017-01-15-kl-135257.png|85973]

I have tried reimporting and rebuilding the app but still the same :-/

Here is the function I run when trying to purchase:

void BuyProductID(string productId){
		
		// If the stores throw an unexpected exception, use try..catch to protect my logic here.
		try
		{
			// If Purchasing has been initialized ...
			if (IsInitialized())
			{
				// ... look up the Product reference with the general product identifier and the Purchasing system's products collection.
				Product product = controller.products.WithID(productId);

				// If the look up found a product for this device's store and that product is ready to be sold ... 
				if (product != null && product.availableToPurchase)
				{
					Debug.Log (string.Format("Purchasing product asychronously: '{0}'", product.definition.id));// ... buy the product. Expect a response either through ProcessPurchase or OnPurchaseFailed asynchronously.
					controller.InitiatePurchase(product);
				}
				// Otherwise ...
				else
				{
					// ... report the product look-up failure situation  
					Debug.Log ("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
				}
			}
			// Otherwise ...
			else
			{
				// ... report the fact Purchasing has not succeeded initializing yet. Consider waiting longer or retrying initiailization.
				Debug.Log("BuyProductID FAIL. Not initialized.");
			}
		}
		// Complete the unexpected exception handling ...
		catch (Exception e)
		{
			// ... by reporting any unexpected exception for later diagnosis.
			Debug.Log ("BuyProductID: FAIL. Exception during purchase. " + e);
		}
	}

Hoping for help in this matter and thanks in advance :slight_smile:

OK, I am stuck on this… I have read some other post on issues like this, although not a Unity issue.

I have tried this, but still no luck:

-(void) purchaseProduct:(ProductDefinition*)productDef
{
    // Look up our corresponding product.
    SKProduct* requestedProduct = [validProducts objectForKey:productDef.storeSpecificId];
    
    if (requestedProduct != nil) {
        UnityPurchasingLog(@"PurchaseProduct: %@", requestedProduct.productIdentifier);
        
        if ([SKPaymentQueue canMakePayments]) {
            [[SKPaymentQueue defaultQueue] removeTransactionObserver:self]; // INSERTED THIS WITH NO LUCK //
            SKPayment *paymentRequest = [SKPayment paymentWithProduct:requestedProduct];
            [[SKPaymentQueue defaultQueue] addPayment:paymentRequest]; // ERROR ON THIS LINE //
        } else {
            UnityPurchasingLog(@"PurchaseProduct: IAP Disabled");
            [self onPurchaseFailed:productDef.storeSpecificId reason:@"PurchasingUnavailable"];
        }
        
    } else {
        [self onPurchaseFailed:productDef.storeSpecificId reason:@"ItemUnavailable"];
    }
}

Tried to insert this: [[SKPaymentQueue defaultQueue] removeTransactionObserver:self];

After reading this post: iphone - In App Purchase Crashes on [[SKPaymentQueue defaultQueue] addPayment:payment] - Stack Overflow

I am not sure if I am placing this correct or if it even can help.

Please help on this…

I also tried with this plugin

https://unionassets.com/iosnative/manage-in-app-purchases-8

and it gives us the same exact problem when it calls the exact same line of code even if the library is totally different (one is UnityPurchasing and this is developed by others).

I honestly think it is a Unity 5.5.0 problem.

@JKasten - OneSignal developer here, we have a build available that should fix this issue. iOS IAP Crash · Issue #30 · OneSignal/OneSignal-Unity-SDK · GitHub

This WORKS :slight_smile: Thanks a lot for your reply… Now I can continue developing my game and earn BIG MONEY :smiley: