如何在 iOS 模拟器或设备上测试 IAP(应用内购买)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16040491/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 23:12:00  来源:igfitidea点击:

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

iphoneiosipadin-app-purchase

提问by openfrog

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

我已经按照 Ray Wenderlich 教程书实现了一个简单的非消耗性应用内购买机制。

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:

SKProductRequest 被创建。它有一个内存地址,但没有其他任何事情发生。没有调用任何委托方法:

- (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.
  • 应用在 iTunes Connect 中完全设置。
  • ITC 中的应用程序状态为“准备上传”
  • 添加了一个非消耗性 IAP。
  • ITC 中 IAP 产品的状态为“准备提交”
  • App ID 是 com.mycompany.myapp 应用程序和 plist。检查了两次。
  • IAP 使用 com.mycompany.myapp.productname(对请求使用完全相同的 ID)。
  • 在 ITC 中创建了一个测试用户帐户。
  • 尚未向 Apple 提交任何内容。
  • 我的 Mac 可以访问互联网。
  • 控制台或屏幕上没有其他消息。

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

Ray Wenderlich 的书没有提到除此之外我必须做任何其他事情。

Only onceI 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.

只有一次我看到 -didFailWithError: 在设备上调用我的委托,但它再也没有出现过。我的代表在设备或模拟器上都不会被调用。我让它运行了几分钟,根本没有任何反应。

iTunes Connect gives this confusing warning:

iTunes Connect 给出了这个令人困惑的警告:

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?

在能够测试应用内购买之前是否需要这样做?

回答by yood

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

在当前版本的 Xcode 5.0 (5A1413) 中,应用内购买在 iOS 模拟器中不起作用。

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

StoreKit(应用内购买)在模拟器中不起作用。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

来源:Xcode 5.0 发行说明 > 已知问题 > iOS 模拟器https://developer.apple.com/library/ios/releasenotes/DeveloperTools/RN-Xcode/xc5_release_notes/xc5_release_notes.html#//apple_ref/doc/uid/TP40001051- CH2-SW303

回答by Ashbay

In iOS simulator documentation it is written :

在 iOS 模拟器文档中它是这样写的:

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

API 限制

在 iOS 模拟器中,API 和功能存在一些限制,包括:

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

不受支持的框架包括:

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.

由于应用内购买需要 Store Kit 才能工作,并且模拟器不支持 Store Kit 框架,因此您无法在 iOS 模拟器中测试 IAP。

More information : iOS Simulator documentation

更多信息:iOS 模拟器文档

回答by Bartu

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.

所以你不能在模拟器中测试应用内购买,你需要一个 iOS 设备。

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.

编辑:据我所知,当您尝试在模拟器上测试 IAP 时会发生这种情况,购买委托不会被调用。

回答by openfrog

I figured out something:

我想出了一点:

I initiated the SKProductRequest immediatelyat the end of AppDelegate's -didFinishLaunching... and it never worked.

我在 AppDelegate 的 -didFinishLaunching 结束时立即启动了 SKProductRequest ……但它从未奏效。

Then I made a delayed call and waited 3 seconds. From then on it started working. So you can't make StoreKit requests immediately after app launch.

然后我打了一个延迟电话,等了 3 秒钟。从那时起它就开始工作了。所以你不能在应用启动后立即发出 StoreKit 请求。

回答by openfrog

Where is your skProductRequest object is declared? Try a global declaration of skProductRequest.

您的 skProductRequest 对象在哪里声明?尝试 skProductRequest 的全局声明。