iPhone In-App Purchase Store Kit error -1003 "Cannot connect to iTunes Store"

Viewed 49253

I've been working on adding in-app purchases and was able to create and test in-app purchases using Store Kit (yay!). During testing, I exercised my app in a way which caused the app to crash mid purchase (so I guess the normal cycle of receiving paymentQueue:updatedTransactions and calling finishTransaction was interrupted).

Now I am unable to successfully complete any transactions and instead am getting only transactions with transactionState SKPaymentTransactionStateFailed when paymentQueue:updatedTransactions is called.

The transaction.error.code is -1003 and the transaction.error.localizedDescription is "Cannot connect to iTunes Store"!

I have tried removing all products from iTunesConnect, and rebuilt them using different identifiers but that did not help. I have also tried using the App Store app to really connect to the real App Store and download some apps so I do have connectivity. Finally, I have visited the Settings:Store app to make sure I am signed out of my normal app store account.

20 Answers

I had a similar situation and dumped the iPhone's network traffic to see what's going on. I found that the normal store was contacted instead of the sandbox. It helped to delete the app from the device, make clean and build/install it again. Apparently something with the development profile had gone wrong.

Update: To dump the network traffic of a non-jailbroken iPhone, just use Internet Sharing on your Mac and configure your iPhone to use your Mac's WiFi. Then tcpdump -n -i en1on your Mac will do the trick.

Add new test user for your app.

In SKPaymentTransactionState tells that SKPaymentTransactionStateFailed before your request is added to server queue.

@class SKPayment;

enum {
    SKPaymentTransactionStatePurchasing,    // Transaction is being added to the server queue.
    SKPaymentTransactionStatePurchased,     // Transaction is in queue, user has been charged.  Client should complete the transaction.
    SKPaymentTransactionStateFailed,        // Transaction was cancelled or failed before being added to the server queue.
    SKPaymentTransactionStateRestored       // Transaction was restored from user's purchase history.  Client should complete the transaction.
};
typedef NSInteger SKPaymentTransactionState;

And on SKPaymentTransaction Class Reference Error Discussion says:

The error property is undefined except when transactionState is set to SKPaymentTransactionStateFailed. Your application can read the error property to determine why the transaction failed.

So, transaction.error.localizedDescription is "Cannot connect to iTunes Store"! is a general error message.. I am also getting this error message regularly while testing my InApp Purchases.

Some tips u can do is,

  1. Retrieve all products from app store using SKProductsRequest and check its response.products contain your requested productIdentifier. for this use,

    SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithArray:[objProducts allKeys]]];
    //pass product identifier array as argument
    [request start];  
    

And Catch response in :

    - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
        NSArray *myProduct = response.products;
}

So that you can decide is you can communicate to app store. and your product id is there.

  1. Make sure that you use In App test user account for testing.
  2. And you use the same app-id provisioning that you configured In App purchase.

thanks

I Did a Clean all Targets in XCode and manually deleted the application off my device, then Build and Run from XCode and it fixed a similar problem (Same error message but different error code:-1009)

The In-App Purchase FAQ says:

Cannot connect to iTunes Store

The "Cannot connect to iTunes Store" issue may be due to one or more of the following reasons:

  • The sandbox may be unreachable.
  • Your app does not have a bundle version (CFBundleVersion). See Setting the Version Number and Build String for more information.
  • Your app is running in the Simulator, which does not support in-app purchase.
  • You are attempting to purchase a product that is unavailable for sale. See Query the App Store for product information before presenting your app’s store UI for more information.

In my case, the error occurred because I was using the Xcode simulator. It started working when I used my device.

Even in the In-App Purchase Programming Guide says to use the development iOS device has a suggested testing step.

Related