How to test IAP (in-app purchase) in iOS Simulator OR on the Device?

34,493

Solution 1

In the current version of Xcode 5.0 (5A1413), In-App purchases will not work in the iOS simulator.

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

Source: Xcode 5.0 Release Notes > Known issues > iOS Simulator https://developer.apple.com/library/ios/releasenotes/DeveloperTools/RN-Xcode/xc5_release_notes/xc5_release_notes.html#//apple_ref/doc/uid/TP40001051-CH2-SW303

Solution 2

In iOS simulator documentation it is written :

API Limitations

Within iOS Simulator, there are some limitations to the APIs and features, including:

Apple Push Services
Privacy alerts for access to Photos, Contacts, Calendar, and Reminders
The UIBackgroundModes key
iCloud document syncing and key-value storage support

Unsupported frameworks include:

External Accessory
Media Player
Message UI 
Event Kit
In UIKit, the UIVideoEditorController class
Store Kit

As in-app purchase needs Store Kit to work and the Store Kit framework is unsupported for Simulator, you can't test IAP in iOS Simulator.

More information : iOS Simulator documentation

Solution 3

Unfortunately there are several things you can not test on the simulator. In App Purchases belongs in that list.

So you can not test In App Purchases in simulator, you need an iOS device for that.

Edit: As far as I can see, that is what happens when you try to test IAP on the simulator, purchase delegates won't get called.

Solution 4

UPDATE OF 2020 YEAR: You can now test in-app purchases in Xcode

Important notice:

Testing StoreKit in iOS, watchOS, or tvOS apps requires Xcode 12 or later running on macOS 10.15 or later. Testing StoreKit in a macOS app requires Xcode 12 or later running on macOS 11 or later.

Apple tutorial here

Solution 5

You can test in-app purchases in Xcode 12 from Apple documentation

https://developer.apple.com/documentation/storekit/in-app_purchase/testing_in-app_purchases_in_xcode?language=objc

And custom manual

https://www.appcoda.com/storekit-testing/

Share:
34,493
openfrog
Author by

openfrog

Thanks a lot to Pascal MARTIN, Gumbo and Quassnoi for their great help. Also many thanks to everyone else answering my questions.

Updated on December 28, 2020

Comments

  • openfrog
    openfrog over 3 years

    I've implemented a simple non-consumable in-app purchase mechanism by following the Ray Wenderlich tutorial book.

    When my app starts, I initiate a product info request:

    self.productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
    _productsRequest.delegate = self;
    [_productsRequest start];
    

    The SKProductRequest gets created. It has a memory address but nothing else happens. None of the delegate methods gets called:

    - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
        NSLog(@"Product info received...");
        NSArray *products = response.products;
        for (SKProduct *product in products) {
            NSLog(@"ID: %@, title:%@, (%f)", product.productIdentifier, product.localizedTitle, product.price.floatValue);
        }
    
        self.productsRequest = nil;
    }
    
    - (void)request:(SKRequest *)request didFailWithError:(NSError *)error {
        NSLog(@"Failed to load list of products");
        self.productsRequest = nil;
    }
    

    I checked twice:

    • App fully set-up in iTunes Connect.
    • Status of app in ITC is "Prepare for Upload"
    • One non-consumable IAP added.
    • Status of IAP product in ITC is "Ready to Submit"
    • App ID is com.mycompany.myapp both for the app and in the plist. Checked twice.
    • IAP uses com.mycompany.myapp.productname (using exact same ID for the request).
    • Created a test user account in ITC.
    • Nothing submitted to Apple yet.
    • My Mac has internet access.
    • There are no other messages in the console or on screen.

    The Ray Wenderlich book doesn't mention I must do anything else besides this.

    Only once I saw a -didFailWithError: call to my delegate on the Device, but it never again appeared. My delegate doesn't get called both on device or simulator. I let it run for minutes with no response at all.

    iTunes Connect gives this confusing warning:

    Your first In-App Purchase(s) must be submitted with a new app version. Select them from the In-App Purchases section of the Version Details page and then click Ready to Upload Binary.

    Is this required prior to being able to test In-App Purchases?

  • openfrog
    openfrog about 11 years
    Editing my question now as I don't get any delegate calls on the device either.
  • thomers
    thomers almost 11 years
    developer.apple.com/library/ios/#documentation/… states: "Store Kit can be tested in the iOS Simulator, except for hosted content downloads."
  • rpitting
    rpitting over 10 years
    As of writing this comment, "Store Kit" is not mentioned anymore in the list of unsupported frameworks in iOS Simulator.
  • Duck
    Duck about 10 years
    @rpitting - yes but IAP is still not working. I am convinced that there are two Apples: one that creates amazing hardware and software for the masses and another Apple controlled by Darth Vader that hates developers and create crappy stuff like Xcode.
  • Urkle
    Urkle over 9 years
    You can test StoreKit in the simulator in Xcode 5.1+.
  • Ironkey
    Ironkey over 3 years
    This is not an acceptable answer. please read meta.stackexchange.com/questions/118582/…