我现在已经尝试了两天在 iOS 应用程序中实现应用程序购买,同样的错误困扰着我。
每次我尝试启动我的 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
而且,是的,我是:
- 在物理设备上测试
- 在测试用户的沙盒环境中
- 具有适当的配置文件
任何帮助表示赞赏,谢谢。