Showing posts with label In-App Purchase. Show all posts
Showing posts with label In-App Purchase. Show all posts

Thursday, June 12, 2014

iOS In-App Purchase Error - “Cannot connect to iTunes Store”

From Macgasm

It's true, In-App Purchases are awesome.  However, setting it up could drive you crazy.  I've personally spent too much time tracking this one “Cannot connect to iTunes Store” error down, so I decided to document the fix here.

If you are trying to do an In-App Purchase you might encounter this error.  It happens just as you send the product in for payment.  For me, its with a line like this:

SKPayment * payment = [SKPayment paymentWithProduct:product];

The weird thing is that the product is found just fine.  So, I know the connection to the iTunes Store is working fine.  However, it won't finalize the purchase.  It throws an error that gives (in my case) one of two errors: 0 or 1003.  You can find this error number by implementing the following (Which is taken from Ray Wenderlich's excellent IPAHelper):

- (void)failedTransaction:(SKPaymentTransaction *)transaction {
    
    NSLog(@"failedTransaction...");
    if (transaction.error.code != SKErrorPaymentCancelled)
    {
        NSLog(@"Transaction error: %@", transaction.error.localizedDescription);
    }
    
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];

}

So, here is how I got both error codes to go away:

Error 0 - You must:
  1. Make sure you have accepted all the documentation terms and conditions within https://itunesconnect.apple.com.  Check under Contracts, Tax and Banking just to make sure.
  2. Make sure you are using a test user within the iPhone you are testing with.  To do this, go to iTunesConnect => Manage Users.  Then add a new test user.  Finally, on the phone you are developing with, go to Settings and sign out as your current user.  Sign in with the new test user you just made.  This should do it!
or

Error 1003 - This one seems to be a networking problem.  To clear this, I recommend you delete the App from your test device, Clean the project in Xcode, rebuild and re-deploy.

Another thing you should check is that Apple's service is up.  If you hit the following address, and you see no response, it's down.

https://sandbox.itunes.apple.com/verifyReceipt?uo=8&at=11ld4k

Once you get In App Purchases working, its pretty sweet.  Good luck, its worth it!