我的代码中有一个反复出现的错误。构建应用程序后,它可以完美运行,直到我单击应用程序内购买然后它崩溃。
这是错误日志:
* 由于未捕获的异常“NSRangeException”而终止应用程序,原因:“* -[__NSArrayM objectAtIndex:]: index 5 beyond bounds for empty array”
* First throw call stack: (0x30fd4f4b 0x3b6a66af 0x30f0b533 0xe03d9 0x11ce01 0x1217d3 0xf696b 0x3379b507 0x319af38b 0x30fa00df 0x30f9fcf7 0x30f9e093 0x30f08c27 0x30f08a0b 0x35bdc283 0x337ac049 0xdee93 0xdede8) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
以及相关代码:
//
// main.m
// Syntax
//
//
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); //This line in green with SIGABRT 1
}
}
当我使用异常断点时,我得到以下结果:
- (void) purchase:(NSString*)purchase_id {
if (![SKPaymentQueue canMakePayments]) {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"inApp purchase Disabled"
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
[alertView release];
return;
}
int ID = 0;
if ([purchase_id isEqual: IAP_500_BYTES_PACK]){
ID = 4;
}
else if ([purchase_id isEqual: IAP_1000_BYTES_PACK])
{
ID = 0;
}
else if ([purchase_id isEqual: IAP_3000_BYTES_PACK]){
ID = 2;
}
else if ([purchase_id isEqual: IAP_7500_BYTES_PACK]){
ID = 5;
}
else if ([purchase_id isEqual: IAP_20000_BYTES_PACK]){
ID = 1;
}
else if ([purchase_id isEqual: IAP_50000_BYTES_PACK]){
ID = 3;
}
else if ([purchase_id isEqual: IAP_ADD_BACKGROUNDS]){
ID = 6;
}
else if ([purchase_id isEqual: IAP_FULL_VERSION]){
ID = 7;
}
SKProduct *productSK = [self.productRes objectAtIndex:ID]; // HERE is thread 1, breakpoint 1.1
if(productSK == nil){
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Cannot connect to iTunes Connect"
delegate:self
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
[alertView show];
[alertView release];
return;
}
在局部变量区域中,它表示:
productSK __NSArrayM * @"0 个对象" 0x14d40300
我的问题是我找不到“productSK”为什么是空的。它设置正确,我认为:
@property (strong, nonatomic) NSMutableArray *productRes;
@synthesize productRes;
你能帮我吗?