1

我正在沙盒模式下测试我的应用内购买,但我不明白为什么即使我点击了购买,应用内购买提醒框仍然弹出...

在我点击“购买”后第二次弹出,我点击“取消”,出现错误:

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;
    }
}
}
4

0 回答 0