I’m trying to set up an SKProductsRequest, but I continually get the error EXC_BAD_ACCESS. I know it has to do with ARC.
In my .h file, I have SKProductsRequestDelegate.
These are the main functions in my .m file:
- (void)requestProUpgradeProductData {
NSSet *productIdentifiers = [NSSet setWithObject:kInAppPurchaseProUpgradeProductId];
productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
productsRequest.delegate = self;
[productsRequest start];
}
#pragma mark -
#pragma mark SKProductsRequestDelegate methods
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
NSArray *products = response.products;
//proUpgradeProduct = [products count] == 1 ? [products firstObject] : nil;
proUpgradeProduct = [products objectAtIndex:0];
if (proUpgradeProduct) {
NSLog(@"Product title: %@" , proUpgradeProduct.localizedTitle);
NSLog(@"Product description: %@" , proUpgradeProduct.localizedDescription);
NSLog(@"Product price: %@" , proUpgradeProduct.price);
NSLog(@"Product id: %@" , proUpgradeProduct.productIdentifier);
}
for (NSString *invalidProductId in response.invalidProductIdentifiers) {
NSLog(@"Invalid product id: %@" , invalidProductId);
}
// finally release the reqest we alloc/init’ed in requestProUpgradeProductData
productsRequest = nil;
[self purchaseProUpgrade];
[[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerProductsFetchedNotification object:self userInfo:nil];
}
When I enabled NSZombieEnabled, then this is what I get: "-[InAppPurchaseManager respondsToSelector:]: message sent to deallocated instance."
Any help would be greatly appreciated.
Thanks!
I finally figured it out! The key is when you synthesize the variable, make sure to do it like this:
And in the .h, it should look like this:
In the .m, make sure to use “self.” when using productsRequest:
There you go!