46

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.

Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213
Rei
  • 1,148
  • 2
  • 12
  • 16
  • Did you find any way to solve your problem? I came across that issue recently and before the sandboxserver went down, the store worked on my iPad. After it went online again, it didn't work anymore. I than copied the same code used in the iPad project to the iPhone project project and tested it with two different iphones and there it worked. But it doesn't seem to work on the iPad app anymore. What's wrong? – NicTesla Jul 21 '11 at 08:32
  • 1
    The "Cannot connect to iTunes Store" error message appears to be a generic one that's used for various different network related error codes when using StoreKit. The specific code -1003 is `kCFURLErrorCannotFindHost` defined in `CFNetworkErrors.h`. – markshep Sep 13 '11 at 14:31
  • 1
    I am having same issue but unfortunately on second chances it confirms the purchase, Any idea??? – Gopal Rathod Nov 20 '12 at 11:54

20 Answers20

40

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.

Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213
  • 3
    Nice, I had to remove the app, and clean the project to get this to work – aryaxt Mar 09 '11 at 07:46
  • I've just had to resort to network sharing and tcpdump after getting a -1003 error. Looks like StoreKit is doing a DNS query for `p40-sandbox.itunes.apple.com.`, but getting `NXDOMAIN` for it (i.e. no DNS entry for that name). So in my particular case it's looking like Apple's fault..... – markshep Sep 13 '11 at 16:01
  • I followed apple's guide to implement in-app purchases and when i try to purchase something i get error code 3 and the description Cannot connect to iTunes Store. I tried to dump the network from the phone and it appears that the phone connects correctly to the sandbox. I also tried adding a new user and i signed out of the store. I don't even get the screen to enter my test user... just the error above. – refaelos Oct 05 '12 at 23:29
  • My IAP implementation was flawless, but somehow I didn't receive any products when testing on some older devices I hadn't used for a longer time. Additionally to the aforementioned, I had to remove all Provisioning Profiles (Settings -> General -> Profiles). After this and a clean build, everything worked fine again. – Tafkadasoh Jan 28 '13 at 17:19
26

If you're getting error 0 "Cannot connect to iTunes Store" (which I realize is not the error -1003 that OP asked about, but a web search for error 0 also leads here), this can be caused by two possible problems:

  1. You're passing in the wrong product identifier. If that's the case, then you'll get error 0 shortly after calling -[SKPaymentQueue addPayment:], before you get the popup asking you to confirm payment.
  2. Your test user has become invalidated. This can happen if you accidentally log into the App Store with your test user. When this happens, you'll get error 0 after entering your password to confirm your payment.

To fix problem #1, pass in the correct product ID. To fix problem #2, create a new test user on iTunes Connect, and optionally delete the old test user.

Adam Rosenfield
  • 390,455
  • 97
  • 512
  • 589
  • A clear, concise description of the problem and the solution. Really helped out after spending god knows how long trying to fix this very issue. Thanks! – CCSab Jul 24 '12 at 20:14
  • Create a new Test user fixed it. Thanks! – Hlung Mar 24 '13 at 20:20
  • Thanks so much @Adam! i was also getting same error. Your Point number 2 solved my problem! – Mohit Nigam May 26 '13 at 13:46
  • fyi i have this same problem and neither of the suggested causes is present. i do get the confirmation dialog and the failure occurs in the response to that... – jheriko Apr 10 '14 at 15:48
15

I had a similar issue, was getting "Cannot connect to iTunes Store" with Code=0. This is how I solved it, after trying every other ritualistic piece of advice found on the Internet from re-downloading my certificates to resetting all my device settings to sacrificing a virgin black goat:

In the target summary for the app, I used to have my version number in the "build" field, but nothing in "version" field. This seemed odd to me, so I moved the version number from "build" to "version". This resulted in the aforementioned error. Moving the version number back to "build" solved the error.

thomax
  • 9,213
  • 3
  • 49
  • 68
  • I also had the Version in the Build field but it didn't help. You probably did something else at the same time. – Kamchatka Oct 07 '11 at 03:46
  • 2
    I can't thank you enough for posting this fix. I tried all the other fixes. Turns out leaving "Build" blank caused it. Thanks! This was actually for error code: 0 – jarrold Jan 17 '12 at 09:52
  • 1
    I was driving nuts and the solution was totally unexpected. You saved me at least 24h of life! Thanks – Fabio Feb 19 '12 at 15:00
  • Thank you so much for posting this! I was also getting error code 0 and none of the other advices helped. – Michal Mar 08 '12 at 20:17
  • 2
    Are kidding me. This actually worked and solved 24 hours of frustration. I was literally moments away from calling around to find a black goat and something as stupid as a blank build field was the problem! Thanks thomax x10000! – AlBeebe Oct 27 '12 at 11:06
13

Add new test user for your app.

HelloWorld
  • 7,156
  • 6
  • 39
  • 36
11

Make sure you have correct date and time set in the Settings. otherwise it fails to make a SSL conenction to the store!!

k3a
  • 1,296
  • 1
  • 15
  • 32
6

I had the same error, and after reading through some threads on the developer forums, I reset the settings on my device (Settings->General->Reset->Reset All Settings), which cleared it up. It seemed drastic, but it worked.

Christopher Pickslay
  • 17,523
  • 6
  • 79
  • 92
2

I had the same error that seemed to pop up out of nowhere (was working fine one day, but then the next day it was giving me these errors about 2 out of every 3 times I tried testing my in-app purchase).

Then I visited the App Store (when trying to make another real purchase), and realized that they had a new user agreement that they wanted me to verify. After I did that, when I went back to my own app and tried out the test purchase again, it was working fine and have had no errors since. So I suspect I was getting the error because they wanted me to verify the new user agreement.

Now the only thing I wonder is if there is a way for my in-app purchase to forward that prompt to my users instead of giving them a mysterious error?

frandogger
  • 314
  • 2
  • 9
1

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

Dharmesh Dhorajiya
  • 3,976
  • 9
  • 30
  • 39
Naveen Shan
  • 9,192
  • 3
  • 29
  • 43
1

What worked for me was to uninstall my app from the test device, then install a fresh copy from Xcode.

lifjoy
  • 2,158
  • 21
  • 19
0

Unfortunately, I ran into a problem that was not documented here. In-App-Purches will not work until you accepted all contracts related to app- and in-app-purcheses. So make sure you (or your customer) set up all contracts in iTunesConnect properly, they must appear in the "Contracts In Effect" section to make your purchaes work.

Thomas Kekeisen
  • 4,355
  • 4
  • 35
  • 54
0

Our problem was that in Itunes Connect we had the wrong bundle identifier. Someone had created the app before hand and we had to edit the app and set its appId to the new one.

trcarden
  • 881
  • 1
  • 9
  • 17
0

I fiddled around with going to the App Store and then back to Settings/Store to Sign Out. I did this 3 times, revisiting my app each time and adding debugging NSLog output, and now I am able to continue testing my in-app purchase code without error -1003. I am not sure the exact reason for this working again, but I am fairly certain is is not a code change on my part as all I was doing was adding NSLogs and re-running my app.

Rei
  • 1,148
  • 2
  • 12
  • 16
0

I had two problems that caused this:

1) I had copied the IAP code from a different (working) app but had missed setting up my observer:

observer = [[IAPHelper alloc] init]; [[SKPaymentQueue defaultQueue] addTransactionObserver:observer];

2) I was logged in to iTunes in the settings of my device. You can only use a test user in the sandbox - I logged out and it worked again.

JanB
  • 904
  • 9
  • 14
0

Yeah, IF you've connected your iPad/iPhone to a different computer initially, and are now using it on another, you absolutely must sign out of store on your iPad, sign in w/ normal account to ITunes on your MAC, then Sync.

Also, make sure your iPad "WIFI" is on...

0

Just log out your iTunes account (don't login your test account now! ) , and start your program. When inapp purchase it ask your login details, you must enter your test account information.

Can Gülse
  • 91
  • 1
  • 3
0

I tried every solution offered in the thread here, but to no avail. In my case, I had a wild-card bundle identifier starting with the same domain name as the one I used while creating the bundle identifier for in-app purchase provisioning profile.

Here is how I fixed the problem and may help you fix yours (See attached):

1) Connect your iPhone to Mac.

2) Under the "Devices" (in Xcode > Window menu > Organizer window) select the "Provisioning Profiles" option for your iPhone. You will see all provisioning profiles currently residing on your iPhone.

3) Carefully remove all provisioning profiles starting with the particular domain name in the bundle identifier (com.MYDOMAIN.*) especially the ones that use wild-card except for the one you create specifically with the ability to do In-App purchase (com.MYDOMAIN.inappidentifier).

4) Install the app afresh and test your implementation with a fresh iTunes connect test user (sandbox)

SCREENSHOT:

enter image description here

programmer
  • 507
  • 5
  • 16
0

I have been stuck for 2 days, here's my solution:

  1. Remove all in-app-products.
  2. Remove new in-app-products.
  3. Create a sandbox tester.
  4. Log out my apple account from device (iPad), and then try to buy the product.
  5. It will ask for login, then re-login with the sandbox tester account.
  6. Purchase goes through.

I think the importance is the sandbox tester account, I have not used it before since I always got error-0.

Mike Bonnell
  • 16,181
  • 3
  • 61
  • 77
0

In my case, I tried everything in the internet, but nothing worked.

Apple actually broke the production payment system, and the sandbox. I just had to wait two days, and it started to work.

Erti-Chris Eelmaa
  • 25,338
  • 6
  • 61
  • 78
0

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.

ricardopereira
  • 11,118
  • 5
  • 63
  • 81
0

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)

wasabi
  • 1,110
  • 10
  • 23