I've now been trying for two days to implement in app purchase in an iOS app, with the same error bugging me.
I get an EXC_BAC_ACCESS error every time I try to start my SKProductsRequest object.
I've read dozens of people having me same error, but none of the solutions seems to work for me.
When I set NSZombieEnabled, i get following error:
[AppShopper respondsToSelector:]: message sent to deallocated instance 0x1d9340
Here's my AppShopper.h:
#import <StoreKit/StoreKit.h>
#define kInAppPurchaseManagerProductsFetchedNotification @"kInAppPurchaseManagerProductsFetchedNotification"
@interface AppShopper : NSObject <SKProductsRequestDelegate>
@property (nonatomic, strong) SKProduct *product;
@property (nonatomic, strong) SKProductsRequest *request;
- (void) requestProductData;
@end
And my AppShopper.m:
#import "AppShopper.h"
@implementation AppShopper
#define productId @"XXX.ProductID.XXX"
@synthesize request = _request;
@synthesize product = _product;
- (void) request:(SKRequest *)request didFailWithError:(NSError *)error{
printf("Error!\n");
_request = nil;
_product = nil;
}
- (void) requestDidFinish:(SKRequest *)request {
printf("Finished request!\n");
}
- (void) requestProductData{
printf("requestProductData\n");
NSSet *productIdentifiers = [NSSet setWithObject:productId];
self.request = [[SKProductsRequest alloc] initWithProductIdentifiers: productIdentifiers];
self.request.delegate = self;
[self.request start];
printf("requestProductData End\n");
}
#pragma mark -
#pragma mark SKProductsRequestDelegate methods
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
printf("productsRequest\n");
NSArray *products = response.products;
self.product = [products count] == 1 ? [products objectAtIndex:0] : nil;
if (self.product)
{
NSLog(@"Product title: %@" , self.product.localizedTitle);
NSLog(@"Product description: %@" , self.product.localizedDescription);
NSLog(@"Product price: %@" , self.product.price);
NSLog(@"Product id: %@" , self.product.productIdentifier);
}
for (NSString *invalidProductId in response.invalidProductIdentifiers)
{
NSLog(@"Invalid product id: %@" , invalidProductId);
}
_request = nil;
_product = nil;
[[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerProductsFetchedNotification object:self userInfo:nil];
}
@end
I try to start the in app purchase with the following code:
AppShopper *shopper = [[AppShopper alloc] init];
[shopper requestProductData];
My output is only:
requestProductData
requestProductData End
2012-09-10 19:43:30.210 MyApp[4327:707] *** -[AppShopper respondsToSelector:]: message sent to deallocated instance 0x1d9340
And, yes I am:
- testing on a physical device
- in sandbox environment with test user
- with a proper provisioning profile
Any help appreciated, thanks.