在 iOS 中的应用内购买测试 [英] In app purchase testing in iOS
问题描述
我正在使用 Xcode 8.0、Swift 3.0 并在我的 iPad 上测试应用购买.我想使用沙盒用户在应用购买中进行测试.
I am using Xcode 8.0, Swift 3.0 and testing in app purchases in my iPad. I want to test in app purchases using sandbox user.
设备设置中没有添加帐号
问题是我没有得到产品列表以响应产品请求代码.请看一下我的代码:
The Problem is I am not getting product list in response of product request code. Please take a look on my code:
let PRODUCT_ID_MY_PRODUCT = "com.company.ProjectName.MyProduct"
// The ProducID in this code and ProducID on iTunes are the SAME. ✔️
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if productID == nil {
productID = PRODUCT_ID_MY_PRODUCT
}
SKPaymentQueue.default().add(self)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
startPurchases()
}
func startPurchases() {
if (SKPaymentQueue.canMakePayments())
{
let productIDs = NSSet(object: self.productID!)
let productsRequest:SKProductsRequest = SKProductsRequest(productIdentifiers: productIDs as! Set<String>)
productsRequest.delegate = self
productsRequest.start()
}
}
// Delegate Methods for SKProductsRequest
func productsRequest (_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
let count : Int = response.products.count
// THE PROBLEM IS HERE.. I AM GETTING COUNT IS ZERO.. MEANS response.products returning null ARRAY
if (count>0) {
let validProducts = response.products
for aProduct in validProducts {
print(aProduct.productIdentifier)
}
} else {
DispatchQueue.main.async(execute: {
UIAlertView(title: "Purchase !", message: "Product not available", delegate: nil, cancelButtonTitle: "OK").show()
return
})
}
}
所以..... 这就是问题所在:我得到 response.products null(数组中没有数据)所以请帮我找到解决方案.可以看到代码中的注释://问题在这里.. 我得到的计数为零.. 意味着 response.products 返回 null ARRAY
So..... That's the problem: I am getting response.products null (no data in array) so Please help me to find the solution. You can see the comments in code: // THE PROBLEM IS HERE.. I AM GETTING COUNT IS ZERO.. MEANS response.products returning null ARRAY
我通过 iTunes Connect 创建了产品.你可以看到下面的图片.所有产品都处于准备提交"状态.
I created products over iTunes Connect. You can see the image below. All the products are in "Ready to Submit" state.
iTunes 上有一些警告
There is some warning on iTunes
Your first In-App Purchase must be submitted with a new app version.
Select it from the app’s In-App Purchases section and click Submit.
Once your binary has been uploaded and your first In-App Purchase
has been submitted for review, additional In-App Purchases can be
submitted using the table below.
还有
我还创建了Sendbox 用户用于测试 应用内购买.见下图:
I also created Sendbox user for testing In-App Purchases. See the image below:
我错过了什么吗?或者错误是什么?错误在哪里?我想使用沙盒用户在应用购买中进行测试
Did I miss something? Or what is the error? And where is error? I want to test in app purchases using sandbox user
推荐答案
我解决了这个问题.有几点需要注意.见下文:
I fixed this. There are some points need to careful about. See below:
- 确保您的开发者帐户符合付费应用程序合同.见下图:
- 在 iTunes Connect 上创建产品.
- 实施应用内购买代码和配置设置.
- 使用分发配置文件创建一个构建版本.
- 在商店上传版本.将构建添加到当前版本.将应用内购买添加到 iTunes Connect 上的版本.
- 然后尝试测试,如果仍然没有,则提交应用程序一次然后取消它.然后尝试在您的设备上进行测试.
- 确保使用沙盒用户进行测试时,您需要从设备设置中已登录的帐户注销,并使用沙盒 ID 登录.
- 一些屏幕截图可能会有所帮助.
这篇关于在 iOS 中的应用内购买测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!