Issue with In

I'm testing my in-app purchase in sandbox mode but I dun understand why the in-app purchase alert box keeps popping up even though i've clicked Buy...

On the second time it pops up after i clicked 'Buy', i clicked 'Cancel' and there was an error:

Thread 1:EXC_BAD_ACCESS (code1, address=0x6000008)

My .m:

-(void)updateCredit{ //Adding to 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/78146.html

上一篇: 只在iPad上崩溃

下一篇: 问题与In