我在我的代碼中有一個重複的錯誤。 構建應用程序時,它會很好地工作,直到我點擊應用程序內購買,然後崩潰。NSArrayM *返回「0個對象」
以下是錯誤日誌:
*終止應用程序由於未捕獲的異常 'NSRangeException',原因: '* - [__ NSArrayM objectAtIndex:]:索引5超出界限爲 空數組'
*第一擲調用堆棧:(0x30fd4f4b 0x3b6a66af 0x30f0b533 0xe03d9 0x11ce01 0x1217d3 0xf696b 0x3379b507 0x319af38b 0x30fa00df 0x30f9fcf7 0x30f9e093 0x30f08c27 0x30f08a0b 0x35bdc283 0x337ac049 0X dee93 0xdede8)的libC++ abi.dylib:與類型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;
你能幫我嗎?
您在哪裏填寫productRes中的值? – sage444
1)'productSK __NSArrayM * @「0對象」0x14d40300'你最好看self.productRes 2)你用ARC嗎? –
@ sage444 這裏是「self.productRes」: self.productRes = [NSMutableArray new]; (SKProduct * product in response.products){ [self.productRes addObject:product]; NSLog(@「%@」,product.productIdentifier); 不,我不使用ARC – Quaxter