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

Related posts:

  1. MKStoreKit 4.0 – Supporting Auto Renewable Subscriptions MKStoreKit started off in a pet project a couple of...
  2. iOS Code: TweetBot like AlertPanels TweetBot is sexy, no one can deny it. One of...
  3. iOS Code: MKiCloudSync – Sync your NSUserDefaults to iCloud with a single line of code Just wrote this class, MKiCloudSync (100 lines of code) that...
  4. iOS5: Migrating your code to NSJSONSerialization using the Adapter Design Pattern In iOS 5, Apple introduced NSJSONSerialization, for parsing JSON strings....

  • 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?