In-App-Purchase takes too long time to show confir

2019-03-25 18:30发布

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?

This is button click:

- (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];

}

buy method:

- (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 method:

- (void)purchaseProduct:(SKProduct *)product
{
    if ([SKPaymentQueue canMakePayments])
{
    SKPayment *payment = [SKPayment paymentWithProduct:product];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
 }
  else
      NSLog(@"Cannot make purchase");
}

3条回答
小情绪 Triste *
2楼-- · 2019-03-25 18:37

This should have nothing at all to do with when an actual user tries to make the purchase, this is because you are running the app in the sandbox environment, also, if your using the simulator this would make it even slower. Also, even when an actual user does make the purchase, the phone has to connect to apple servers, find the IAP from the millions of others by it's id, make sure information matches, send this information back to the phone securely using encryption, then the phone has to check if the encryption matches a success message, then send the success back to the user. As you can see, it is normal that there is a little time before a confirmation message is sent back.

I recommend adding a loading screen in the SKPaymentTransactionStatePurchasing method, telling the user that you are in fact fetching the information. Again, this is 100% normal what you are seeing, Apple has to do a lot of checks, and verify a lot of things before it can send back a confirmation message. Hope this helps!

查看更多
Bombasti
3楼-- · 2019-03-25 18:59

A reason might be, that you are in the sandbox environment, which has occasional hiccups. Or your app could be doing some heavy lifting while performing the purchase, which slows down the device (but runs fast on the more powerful simulator).

查看更多
相关推荐>>
4楼-- · 2019-03-25 19:03

Are you in the sandbox environment? If so,that is a normal situation.I am in china,it always takes more than 10 second when I test IAP on device.I think it is not your technical issue.Believe yourself.:)

查看更多
登录 后发表回答