我在用Xcode 8.0、斯威夫特 3.0并在我的 iPad 上进行应用程序购买测试。我想使用沙盒用户测试应用程序购买。
设备设置中没有添加账户
问题是我没有获取产品列表来响应产品请求代码。
请看一下我的代码:
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 返回空数组
我通过 iTunes Connect 创建了产品。您可以看到下图。所有产品均在“准备提交”状态。
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.
And
我还创建了用于测试的发送箱用户应用内购买。见下图:
我错过了什么?或者说错误是什么?错误在哪里?我想使用沙盒用户测试应用内购买