问题描述
我遇到了以下问题:当我的应用程序在设备上运行并且我点击购买"按钮时,这会触发应用内购买机制,显示标准确认UIAlertView
最多需要十秒钟, : 你要买吗...".我以前从未见过这样的行为.通常它会立即发生.因此,首先我认为这可能是由于互联网连接状况不佳或类似原因造成的,但是模拟器使用了相同的WiFi网络,并且运行良好,警报视图可以按原样立即显示.因此问题可能出在其他地方.有人解决了这个问题吗?
I have encountered the following issue: when my app runs on a device and I tap BUY button, which triggers In-App-Purchase mechanism it takes up to ten seconds to show the standard confirmation UIAlertView
, the one which says: "Do you want to buy...". I have never seen such a behaviour before. Usually it happens immediately. So first I thought it might be due to poor internet connection or something like this, but the simulator uses the same WiFi network and it works perfectly, the alert view is presented instantly as it should be. So the problem probably lies somewhere else. Did anyone solve this issue already?
这是单击按钮:
- (void)buyItemTapped:(id)sender
{
[[InAppPurchaseManager sharedInstance] buy:[NSString stringWithFormat:@"com.mycompany.myapp.unit%d", [sender tag] + 1]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(transactionFailed)
name:TRANSACTION_FAILED_NOTIFICATION
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(productPurchased:)
name:PRODUCT_PURCHASED_NOTIFICATION
object:nil];
}
购买方式:
- (void)buy:(NSString *)identifier
{
SKProduct *product = [self.products objectForKey:identifier];
if (product)
[self purchaseProduct:product];
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Invalid Product Identifier"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
purchaseProduct方法:
purchaseProduct method:
- (void)purchaseProduct:(SKProduct *)product
{
if ([SKPaymentQueue canMakePayments])
{
SKPayment *payment = [SKPayment paymentWithProduct:product];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
else
NSLog(@"Cannot make purchase");
}
推荐答案
这与实际用户尝试购买时的体验无关.发生这种情况是因为您正在沙盒环境中运行该应用程序.实际上,使用模拟器会使它变得更慢.
This should have nothing to do with what an actual user experiences when they try to make the purchase. This is happening because you're running the app in the sandbox environment. In fact, using the simulator makes it even slower.
但是,即使实际用户进行了购买,手机也必须连接到Apple的服务器,找到IAP,然后将IAP数据安全地发送到设备.因此,如您所想,正常情况下,确认消息会在短时间内返回.
However, even when an actual user does make the purchase, the phone has to connect to Apple's servers, find the IAP, and then send the IAP data to the device securely. So, as you could imagine, it is normal that there is a little time before a confirmation message is sent back.
我建议在SKPaymentTransactionStatePurchasing
方法中添加一个加载屏幕,告诉用户您实际上正在获取信息.这很简单,只需将购买"按钮更改为正在购买..."即可.
I recommend adding a loading screen in the SKPaymentTransactionStatePurchasing
method, telling the user that you are in fact fetching the information. This could be as simple as changing the "Purchase" button to say "Purchasing...".
同样,这是您所看到的100%正常现象,但这主要是因为您使用的是沙箱和/或模拟器. Apple必须先做很多检查,并核实很多事情,然后才能发送回确认消息,因此,您应该至少期待一些小的延迟(就像从网站上获取信息一样).
Again, this is 100% normal what you are seeing, but is mostly because you're using the sandbox and/or simulator. Apple has to do a lot of checks, and verify a lot of things before it can send back a confirmation message, so you should expect at least some minor delay (as if you were fetching information from a website).
这篇关于应用内购买花费的时间太长,无法显示确认警报视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!