38

In IOS6, I was successfully making in-app purchases in my app.

I downloaded IOS/ and Xcode 5 Beta and tried to open the same project.

My code to get products from app store is:

- (void)requestProductsWithIdentifiers:(NSSet*)identifiers
{
        @synchronized(self)
    {
            DebugLog(@"requesting products with identifiers: %@", identifiers);

            self.productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:identifiers] ;
            self.productsRequest.delegate = self;
            [self.productsRequest start];
    }
}

But it returns an error:

[IAPHelper request:didFailWithError:](114): request did fail with error: <SKProductsRequest: 0xb846a10> / Error Domain=SSErrorDomain Code=2 "Cannot connect to iTunes Store" UserInfo=0xb846b10 {NSLocalizedDescription=Cannot connect to iTunes Store}

Where can be the problem?

Burak
  • 5,706
  • 20
  • 70
  • 110
  • 1
    I encountered same problem with Xcode 5 Beta on iOS 7 Simulator, If I run the project with Xcode 4.6.3 and on iOS 6 Simulator, everything is fine. – TS.xy Aug 17 '13 at 09:55
  • any luck finding a real solution to this instead of the many nothings mentioned in the comments and 'answers'? i have recently submitted a new version of app to the store, made no changes to code and get a very similar problem: StoreKit: cancelled transaction error: Error Domain=SKErrorDomain Code=2 "Cannot connect to iTunes Store" UserInfo=0x1857dde0 {NSLocalizedDescription=Cannot connect to iTunes Store}, errorCode: 2 - only when finalising purchase - everything else (getting product list etc.) works as expected. – jheriko Apr 10 '14 at 13:58

6 Answers6

59

Apple blocked testing in-app purchases...

Here is the link to the release notes https://developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html#//apple_ref/doc/uid/TP40001051-CH1-SW578

See: iOS Simulator section

StoreKit (In-App purchases) will not work in the Simulator. 13962338

Very sad...

Cœur
  • 37,241
  • 25
  • 195
  • 267
Arkady
  • 3,196
  • 24
  • 19
  • 2
    That does not explaing problems while testing in-app purchases not-in-simulator. That was not problem with some concrete device: I've tried in-app purchases on many devices, and they weren't working on any of them. I could even get product information, but I could not make any in-app purchase in sandbox. – Oleksandr Palii Sep 23 '13 at 22:20
  • 6
    Apple allows (even requires) to test in-app purchases on the device using special test user, here is the link to [documentation](https://developer.apple.com/library/ios/documentation/LanguagesUtilities/Conceptual/iTunesConnect_Guide/13_ManagingIn-AppPurchases/ManagingIn-AppPurchases.html). See **Testing Your In-App Purchases** section – Arkady Sep 24 '13 at 05:52
  • 4
    Thanks, but I know that. I meant, one day everything worked, next day in-app purchases did not work, and on the next day everything worked again, without any changes from my side. That's why some time before I was talking about problems at the Apple's side in my answer. – Oleksandr Palii Sep 24 '13 at 14:14
  • 2
    It's so sad I'm gonna cry ;___; – Hlung Dec 05 '13 at 06:42
  • I see the same. Impossible to test in-app purchase. I see error code 109 - cannot connect to iTunes. Half of the development time I'm trying to convince my iPad to connect to iTunes. – Pavel Jan 19 '14 at 07:22
  • It's worth noting that it's actually listed under Known Issues. So maybe one day they'll get around to putting it back in. – rob5408 Apr 09 '14 at 14:06
  • Updated link to "Testing In-App Purchase Products": https://developer.apple.com/library/ios/documentation/LanguagesUtilities/Conceptual/iTunesConnectInAppPurchase_Guide/Chapters/TestingInAppPurchases.html – Aaron Ash Mar 02 '16 at 14:33
  • Updated Link version 2 to "Testing In-App Purchase Products" https://developer.apple.com/help/app-store-connect/test-in-app-purchases-main/test-in-app-purchases – Sayed Muhammad Idrees Mar 27 '23 at 15:01
12

I encountered the same problem recently after installing xcode 5 and the iOS 7 simulator.

Previously SKProductRequests worked in the simulator, but now they fail with error code 2. (They still work on devices).

I'm not sure what is causing this, but my solution was to download the iOS 6.1 simulator. xcode Preferences->Downloads->Components and select the iOS 6.1 simulator.

After that I had to select the iOS 6.1 simulator as my device target, delete the app from the simulator, then compile and run it again. Now the SKProductRequests returned the product info as expected.

I tried switching back to the iOS 7 simulator but SKProductRequests started failing again.

adrian
  • 151
  • 4
6

Update: Testing in-app purchases in the simulator appears to work in the Xcode 6 beta

benzguo
  • 176
  • 1
  • 4
  • 4
    While in the iOS 7 Simulator I'm encountering errors attempting to request products, it successfully fetches them in the iOS 8 Simulator. However, when I sign in to restore a purchase, it fails to connect with the same "Cannot connect to iTunes Store" error. In short: use a physical device to test IAPs. – Jordan H Jul 28 '14 at 01:30
  • I am having a similar problem. The simulator will get the products, but fails on purchase. Everything works fine on the actual device (5s) – The Way Sep 18 '14 at 14:54
  • I confirm this is exactly what's happening to me too. – darbid Apr 01 '15 at 20:53
  • Same here! I can fetch the products but can't purchase them with a sandbox account in simulator. It works fine on a device though! – Raphael May 29 '15 at 15:18
  • 1
    Also doesn't work in xcode 7.1.1 /simulator 9.1 either. Can fetch products but purchase fails w/ "Cannot connect to itunes store". This is known per https://developer.apple.com/library/prerelease/ios/technotes/tn2413/_index.html – farhadf Dec 01 '15 at 18:03
2
  1. Verify that you're signed out from iTunes & App Store (Settings -> iTunes & App Store -> touch the Apple ID -> Sign Out)

  2. Go back to your app, do the purchase again and sign in with a test user account, as development builds access the Sandbox store and not the production store.

Tafkadasoh
  • 4,667
  • 4
  • 27
  • 31
1

With the GM Release of XCode 5, as Arkady said, you can't test in app purchases in the simulator. However, I was able to test in-app purchases on my iPad 2 running iOS 7.0.2 by signing out from iTunes and App Store (as Tafkadasoh mentions) and then running the application on the device from XCode. When I got to the in-app purchase, I was prompted to enter an Apple ID and when I entered the test user account information (that I had created in itunes connect), I was able to successfully run through an in-app purchase in sandbox mode.

hypermiler
  • 113
  • 2
  • 4
0

The release notes does not say they have blocked in-app purchase, the text states there is a known bug "StoreKit (In-App purchases) will not work in the Simulator. 13962338", if I am reading it correctly. Presumably 13962338 is the bug number. Mind you if it was a politician making the statement I might agree with you :-)

PS Since they have removed iTunes settings it does make it a bit tricky to do in-app purchases.

PPS Perhaps we should all start file bug reports.

user667522
  • 29
  • 4