gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 19:07:46 27 4
gpt4 key购买 nike

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

在我请求产品信息后,有时由于某种原因 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com