SKProductsRequest返回0个产品的原因是什么? [英] Reasons for SKProductsRequest returning 0 products?
问题描述
我正在尝试设置IAP,但在使用SKProductsRequest调用检索产品后,我的委托中的SKProductsResponse数组的计数为0.这是我的核对清单:
- 测试产品已添加到iTunes连接中
- 产品的包ID与应用包ID相匹配(并且不使用通配符)
- SKProductRequest中设置的产品标识符与iTunes连接上创建的产品相匹配
- 自iTunes产品在iTunes连接上创建以来,我等了好几个小时
- 供应配置文件启用IAP
- 按照各种教程中的所有步骤操作,例如
2)iTunes Connect - >协议,税务和银行业务 - >主协议 - >付费应用程序 - >联系信息/银行信息/税务信息(应填写)
3)测试代码
class ViewController:UIViewController {
var requestProd = SKProductsRequest()
var products = [SKProduct]()
override func viewDidLoad(){
super.viewDidLoad()
validateProductIdentifiers()
}
}
扩展名ViewController:SKProductsRequestDelegate {
func validateProductIdentifiers( ){
let productsRequest = SKProductsRequest(productIdentifiers:Set([candy100,someOtherProductId]))
//保持对请求的强引用。
self.requestProd = productsRequest;
productsRequest.delegate = self
productsRequest.start()
}
// SKProductsRequestDelegate协议方法
public func productsRequest(_ request:SKProductsRequest,didReceive响应:SKProductsResponse){
self.products = response.products
for response.invalidProductIdentifiers {
print(invalidIdentifier)
}
}
}
I'm trying to set up IAP but after making a call to retrieve the products using SKProductsRequest the SKProductsResponse array within my delegate has a count of 0. Here's my checklist:
- Test product has been added to iTunes connect
- The product's bundle id matches the app bundle id (and its not using a wildcard)
- The product identifier set in the SKProductRequest matches the product created on iTunes connect
- I've waited several hours since the product was created on iTunes connect
- The provisioning profiles enable IAP
- Followed all steps in various tutorial such as http://troybrant.net/blog/2010/01/in-app-purchases-a-full-walkthrough/ etc.
- Have deleted app from device, relaunched Xcode, rebuilt etc. etc.
Any other suggestions as to why the fetched product count is zero?
I don't believe this will be a coding issue, but here it is anyway:
… NSSet *productIdentifiers = [NSSet setWithObjects:@"redacted", nil]; self.productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers]; self.productsRequest.delegate = self; [self.productsRequest start]; … - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response { NSArray *products = response.products; NSLog(@"Product count: %d", [products count]); for (SKProduct *product in products) { NSLog(@"Product: %@ %@ %f", product.productIdentifier, product.localizedTitle, product.price.floatValue); } }
解决方案Check all 3 things in the list below
1) check your product identifiers - they must be exactly the same that you have in your code and in iTunes Connect -> My Apps -> YourAppName -> Features -> In-App Purchases 2) iTunes Connect -> Agreements, Tax, and Banking -> Master Agreements -> Paid Applications-> Contact Info / Bank Info / Tax Info (should be filled) 3) code to test itclass ViewController: UIViewController { var requestProd = SKProductsRequest() var products = [SKProduct]() override func viewDidLoad() { super.viewDidLoad() validateProductIdentifiers() } } extension ViewController: SKProductsRequestDelegate { func validateProductIdentifiers() { let productsRequest = SKProductsRequest(productIdentifiers: Set(["candy100", "someOtherProductId"])) // Keep a strong reference to the request. self.requestProd = productsRequest; productsRequest.delegate = self productsRequest.start() } // SKProductsRequestDelegate protocol method public func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) { self.products = response.products for invalidIdentifier in response.invalidProductIdentifiers { print(invalidIdentifier) } } }
这篇关于SKProductsRequest返回0个产品的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!