When using MKStoreKit or any other equivalent framework or regular In App Purchases’ StoreKit.framework, If you are getting a problem like this,

Cannot connect to iTunes Store Code: Error code: 0

 

Error code 0 is SKErrorUnknown. It probably means connection couldn’t be established from your device to Apple.

The number one reason for this is, you are using a jailbroken iPad that updated the hosts file to block traffic to gs.apple.com

The second reason which I found today is that you are making the product purchase call on a delegate callback instead of the main thread.

A common example of this is showing the list of products on a UITableView and making the purchase on the UITableViewDelegate. Or showing an additional UIAlertView prompt and making the real purchase on the delegate call back.

StoreKit.framework internally using NSURLConnection and to quote from Apple Documentation

By default, for the connection to work correctly, the calling thread’s run loop must be operating in the default run loop mode. See scheduleInRunLoop:forMode: to change the run loop and mode.

You don’t have control over StoreKit code to change the run loop. As such, you should ensure that, calls to add your product to the queue are done on the main thread.

I’ll fix this in MKStoreKit and commit it to Github. Watch the repo or this blog post for updates.

Mugunth


Follow me on Twitter

  • Jesua

    Hello, thank you for nice article. I still get the same error message. I spent whole weekend trying to solve this problem without success. I wrote app with MKStoreKit and and without, reset iPad, restore iPad, generate new APP ID, submit new binary…  always with this error message.

    I can get product list right, but can’t buy them. I complete restore my iPad and add product to queue in main thread.

    Please – some suggestions

    • dave

      i was having the same problem.  i created a new test user and all of a sudden was able to make the purchase.  sandbox seems quirky.

      • Jesua

        I solve this problem. You must create test user from USA not from Europe!

  • Second_gear

    I’m getting this issue in 4.0. Is this fixed yet?

  • Second_gear

    I’m getting this issue in 4.0. Is this fixed yet?

  • Surbhi

    Please login with the test user created in sandbox environment