iphone - 支付队列 :updatedTransactions gets called when it shouldn't?

标签 iphone xcode4.2 in-app-purchase storekit

我在应用内购买时遇到了奇怪的问题...

在我请求产品信息后,有时由于某种原因 paymentQueue:updatedTransactions 会被自动调用。

在我商店的 viewDidLoad 方法中,我初始化并启动请求:

- (void)viewDidLoad
{
    [super viewDidLoad];

    productsArray = [[NSArray alloc] init];

    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];

    NSSet *productIdentifiers = [NSSet setWithObjects:PRODUCT_ID, nil];
    productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
    productsRequest.delegate = self;
    [productsRequest start];
}

然后我得到回复:

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
    productsArray = [[NSArray alloc] initWithArray:response.products];

    NSLog(@"Products Count: %d",[productsArray count]);
    NSLog(@"Invalid Products Count: %d",[response.invalidProductIdentifiers count]);

    if ([productsArray count] > 0)
    {
        NSLog(@"Product title: %@" ,[productsArray objectAtIndex:0]);
        [self hideLoadingView];


    } else {
        UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"No products found"
                                                            message:@"There might have been a problem. Please try again soon." delegate:self 
                                                  cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
        [alertView release];

        [self hideLoadingView];
        [purchaseBtn setEnabled:NO];

    }

    [productsRequest release];

    [[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerProductsFetchedNotification object:self userInfo:nil];

}

这是我希望流程结束的地方,并等待用户点击购买按钮...但有时(例如 70% 的时间),我会在以下位置弹出用户名/密码警报框命令购买该元素...但用户没有点击任何内容...(如果用户已经“登录”,那么它会在不询问的情况下购买该元素。这不应该是这样的。

这是有时会自动调用的方法:

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

这是购买按钮的 IBAction:

-(IBAction)buyItem:(id)sender {

    [self showLoadingView];

    SKPayment *payment = [SKPayment paymentWithProductIdentifier:[(SKProduct *)[productsArray objectAtIndex:0] productIdentifier]];
    [[SKPaymentQueue defaultQueue] addPayment:payment];

    }        
}

我认为 StoreKit 的用户/密码警告框不应该显示,直到我调用 defaultQueue 的“addPayment”方法,该方法仅出现在 IBAction 中。

有什么想法吗? 谢谢!

最佳答案

一旦你添加了事务观察者,iOS 就会检查默认队列中是否有任何未完成的事务(这意味着你没有完成它),因此每次有事务时它都会显示警报框,直到你完成为止如果您没有执行任何操作来添加新付款。

关于iphone - 支付队列 :updatedTransactions gets called when it shouldn't?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9643066/

相关文章:

iphone - 从 CVPixelBuffer Reference 获取所需数据

iphone - 如何从 iPhone 的图库中删除选定的照片?

iphone - 为什么不调用 viewWillDisappear 或 viewDidAppear?

objective-c - 无法使用 ABNewPersonViewController 在通讯录中显示

按钮在 IOS5 中不起作用

objective-c - 为什么 ARC 仍然需要 @autoreleasepool?

android - 测试Android应用内购买:购买的订阅会自动取消而不是自动续订吗?

ios - 消耗品与非消耗品

iphone - 是否可以使用 Core Animation 淡出 UIBarButtonItem?

android - Google Play Alpha 版本 - 如何测试应用内购买