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");
}