问题与In
我正在沙箱模式下测试我的应用内购买,但我明白为什么即使点击了购买,应用内购买提醒框仍会弹出
第二次点击'购买'后弹出,我点击'取消',出现错误:
Thread 1:EXC_BAD_ACCESS (code1, address=0x6000008)
我的.m:
- (void)updateCredit {//添加到plist NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString * documentsDirectory = [paths objectAtIndex:0]; NSString * path = [documentsDirectory stringByAppendingPathComponent:@“data.plist”];
NSMutableArray *currPlist = [[NSMutableArray alloc] initWithContentsOfFile: path];
NSString *lastEx = [currPlist objectAtIndex:0];
int lastScore = [[currPlist objectAtIndex:1] intValue];
int numberOfTries = [[currPlist objectAtIndex:2] intValue];
int totalScore = [[currPlist objectAtIndex:3] intValue];
int avg = [[currPlist objectAtIndex:4] intValue];
int credit = [[currPlist objectAtIndex:5] intValue];
credit += 10;
NSMutableArray *updatePlist = [[NSMutableArray alloc] init];
[updatePlist addObject:lastEx];
[updatePlist addObject:[NSNumber numberWithInt:lastScore]];
[updatePlist addObject:[NSNumber numberWithInt:numberOfTries]];
[updatePlist addObject:[NSNumber numberWithInt:totalScore]];
[updatePlist addObject:[NSNumber numberWithInt:avg]];
[updatePlist addObject:[NSNumber numberWithInt:credit]];
[updatePlist writeToFile: path atomically:YES];
}
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
break;
case SKPaymentTransactionStatePurchased:
[[SKPaymentQueue defaultQueue]finishTransaction:transaction];
[self updateCredit];
[self dismissModalViewControllerAnimated:YES];
break;
case SKPaymentTransactionStateRestored:
[[SKPaymentQueue defaultQueue]finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
if (transaction.error.code != SKErrorPaymentCancelled) {
UIAlertView *alert2 = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Error updating credit" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert2 show];
}
[[SKPaymentQueue defaultQueue]finishTransaction:transaction];
break;
default:
break;
}
}
}
链接地址: http://www.djcxy.com/p/78145.html
上一篇: Issue with In
下一篇: Help with save file to Documents NSMutableArray with NSObjects