Following in App Purchase, App Crashing on Startup. Productidentifier=Nil

Following in app purchase, app crashing on startup. productIdentifier=nil?

I've run into a similar issue when the transaction is in the SKPaymentTransactionStateRestored. My testing has indicated this might be an issue with IOS 7.0.3, but I have not been able to verify this.

StoreKit keeps a persistent list of transactions that your application must finish. As you've noted the transaction will be reported on every startup until it is finished.

The solution that we implemented is to check if the product identifier is nil before usage from the entry point:

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions

Even when we received a transaction with a nil product identifier we were able to successfully call finishTransaction.

I hope this helps.

In App Purchase (IAP) process appears to be crashing the app on launch for one of my users

We recently started getting similar crash reports from some of our users, the issue is that the productId being passed here is 'nil', which will cause a crash b/c it will be used as a key and a hash will need to be computed down the line.

However, its still not clear to us why it is sometimes 'nil'. But at least the crash can be avoided by guarding against the possibility that the productId can be nil at times.

App crashing when buying in-app purchase

Problem solved!

I had to remove the TransactionObserver when closing the view.

    public override void ViewWillDisappear (bool animated)
{
base.ViewWillDisappear (animated);

//Prevents crash when re-opening view
SKPaymentQueue.DefaultQueue.RemoveTransactionObserver (theObserver);
}

in app purchases - device crash

[__NSSetM addObject:]: object cannot be nil

This means that you have a mutable set that you are calling addObject: on, but the variable you are passing in is nil.

In the code you post, the only place you call this is in the line:

[_purchasedProductIdentifiers addObject:productIdentifier];

...so wherever you are calling provideContentForProductIdentifier:, you are passing it nil.

In app purchases crashing app when changing scenes

Having all the StoreKit code in your game scene makes it more difficult to isolate the issue you're having. I'd suggest you make a new swift file let's call it PurchaseService with a static instance like this:

class PurchaseService {
static let session = PurchaseService()
var products = [SKProduct]()
// code
}

You can implement all your purchasing related logic here. I usually use a getPurchases function to load the available purchases from the store and call it from the application function of the AppDelegate.swift file. This ensures that your purchases get loaded very early and will be ready the first moment you need them (because you make a static instance you can refer to it any time you need to do a purchase through PurchaseService.session...)

To get the prices you can use a function that iterates through your products variable and checks the product id:

func price(for productID:String)->Double{
if products.count>0 {
for product in products {
if product.productIdentifier == productID {
return product.price.doubleValue
}
}
}
}

If you comply to the SKProductRequestDelegate protocol you don't need to conditionally cast self to it:

 // unnecessary:  request.delegate = self as? SKProductsRequestDelegate
request.delegate = self

Wondering if you made the productRequest method public because by the time the request returns the SKProductResponse object self is no longer available.

Regarding Objective-C code in your project: I see you might be using Firebase (from your console messages I'm inferring) and it has some objective-c bits and pieces.



Related Topics



Leave a reply



Submit