私は現在、iOSアプリでアプリ内購入を実装するために2日間試みてきましたが、同じエラーが私を悩ませています。
SKProductsRequest オブジェクトを開始しようとするたびに、EXC_BAC_ACCESS エラーが発生します。
私は同じエラーを抱えている何十人もの人々を読みましたが、どの解決策もうまくいかないようです。
NSZombieEnabled を設定すると、次のエラーが発生します。
[AppShopper respondsToSelector:]: message sent to deallocated instance 0x1d9340
ここに私の 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
そして、私の 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
次のコードでアプリ内購入を開始しようとしています。
AppShopper *shopper = [[AppShopper alloc] init];
[shopper requestProductData];
私の出力は次のとおりです。
requestProductData
requestProductData End
2012-09-10 19:43:30.210 MyApp[4327:707] *** -[AppShopper respondsToSelector:]: message sent to deallocated instance 0x1d9340
そして、はい、私は:
- 物理デバイスでのテスト
- テストユーザーのサンドボックス環境で
- 適切なプロビジョニング プロファイルを使用する
助けていただければ幸いです。