Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 558
openfrog Avatar asked Apr 16 '13 15:04

openfrog


People also ask

Can I test in app purchase on simulator iOS?

It is impossible to make a purchase on a simulator (it is only possible to request a list of available purchases). To test purchases, you first need to set up products on App Store Connect and then use the user's sandbox environment and a real device. In this case, purchases for the developer are free.

Can you test IAP on simulator?

You can either add new IAP under same group, or create new group, or even delete the existing one. The final step now is making this configuration file is available for testing in the simulator. What you need to do is using the storekit in our debug options in our scheme.

How do I test in app purchases iOS?

Sign In to the App Store with Your Sandbox Apple ID In iOS and iPadOS, the sandbox account appears in Settings > App Store after the first time you use the device to attempt a purchase in a development-signed app. There's no need to sign out of the non-Sandbox Apple ID.

How do I add IAP purchasable items to my App?

In a web browser, go to the your app's page on the Apps & Games Developer Portal. Add your IAP purchasable items to your app, if you have not already done so. Click the link to download your JSON Data File. Name the downloaded file "amazon.sdktester.json".

How do I implement in-app purchases on iOS devices?

Implementing in-app purchases requires the application to utilize the StoreKit API on the device. StoreKit manages all communication with Apple’s iTunes servers to get product information and perform transactions. The provisioning profile must be configured for in-app purchasing and product information must be entered in iTunes Connect.

How to test IAP items in JSON file?

From the App Tester main menu, tap the IAP Items in JSON File option to display a human-readable list of the item data in the JSON file. Familiarize yourself with the App Tester tool and the test options for IAP:

How do I build an app on a test device?

If your test device has macOS 11.1 or earlier installed, sign out of the Mac App Store, then build your app in Xcode and launch it from Finder. The first time you make a purchase in a development-signed app, sign in to the App Store using your Sandbox Apple ID to begin testing.


2 Answers

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

like image 154
yood Avatar answered Sep 23 '22 10:09

yood


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

like image 26
Ashbay Avatar answered Sep 23 '22 10:09

Ashbay