iOS 7 Sprite Kit应用内购买块呈现场景

时间:2014-04-11 11:04:00

标签: ios sprite-kit 2d-games

在我的游戏设置屏幕中,我提供应用内购买更多面包车玩家可以在游戏中驾驶。如果我发起购买请求,忽略交易失败或成功,在我返回主菜单并开始游戏后,将不会显示新场景(即使是空白场景)。 然后我需要关闭应用程序(从内存中删除)并再次打开它以恢复正常状态。 有谁知道可能是什么问题?为什么一些应用程序内购买会阻止呈现新场景?

非常感谢,我正在处理这个问题好几天。

这是启动场景的代码:

SKTransition *reveal = [SKTransition revealWithDirection:SKTransitionDirectionLeft duration:0.4];
    ICMyScene *newScene = [[ICMyScene alloc] initWithSize: winSize];

    [self.scene.view presentScene: newScene transition: reveal];

这是购物代码:

- (void)buyProduct:(SKProduct *)product {

    NSLog(@"Buying %@...", product.productIdentifier);

    SKPayment * payment = [SKPayment paymentWithProduct:product];
    [[SKPaymentQueue defaultQueue] addPayment:payment];

}
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    for (SKPaymentTransaction * transaction in transactions) {
        switch (transaction.transactionState)
        {
            case SKPaymentTransactionStatePurchased:
                [self completeTransaction:transaction];
                break;
            case SKPaymentTransactionStateFailed:
                [self failedTransaction:transaction];
                break;
            case SKPaymentTransactionStateRestored:
                [self restoreTransaction:transaction];
            default:
                break;
        }
    };
}

- (void)completeTransaction:(SKPaymentTransaction *)transaction {
    NSLog(@"completeTransaction...");

    [self provideContentForProductIdentifier:transaction.payment.productIdentifier];
    [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

    [[NSNotificationCenter defaultCenter] postNotificationName:nRemoveAdsNotif object:nil userInfo:nil];

}

- (void)restoreTransaction:(SKPaymentTransaction *)transaction {
    NSLog(@"restoreTransaction...");

    [self provideContentForProductIdentifier:transaction.originalTransaction.payment.productIdentifier];
    [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}

- (void)failedTransaction:(SKPaymentTransaction *)transaction {

    NSLog(@"failedTransaction...");
    if (transaction.error.code != SKErrorPaymentCancelled)
    {
        NSLog(@"Transaction error: %@", transaction.error.localizedDescription);
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Transaction error" message:transaction.error.localizedDescription delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
        [alert show];
    }

    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}

0 个答案:

没有答案