ios - Swift 3 中 IAP 的产品请求?

标签 ios swift in-app-purchase

我试图在我的应用程序中为我的 IAP 设置产品请求,但我在正确定义请求时遇到了问题。这是代码:

let productsRequest: SKProductsRequest = SKProductsRequest(productIdentifiers: self.productId as! Set<String>)

self.productRequest是在itunesConnect中创建的IAP的字符串标识

报错

Cast from 'String' to unrelated type 'Set' always fails

如果不是 IAP 的标识字符串,我应该将什么传递到请求中?我运行该应用程序,它返回 0 个产品

编辑:新的完整功能代码:

let productIdentifiers: Set<ProductIdentifier> = ["com.Personal.LiftApp.RemoveGoogleAds"]
        let productsRequest = SKProductsRequest(productIdentifiers: productIdentifiers)
        productsRequest.delegate = self
        productsRequest.start()

最佳答案

你有这个错误是因为 ProductIdentifier 必须是一个字符串:

typealias ProductIdentifier = String

你应该传递一组字符串:

let productIdentifiers: Set<ProductIdentifier>

所以,你应该调用:

productsRequest = SKProductsRequest(productIdentifiers: productIdentifiers)

为了帮助您更好地理解如何制作它,请看这个例子:

let productIdentifiers: Set<ProductIdentifier> = [id_of_the_first_in_app_purchase, id_of_the_second_in_app_purchase]

关于ios - Swift 3 中 IAP 的产品请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42628387/

相关文章:

ios - 无法在 iOS 设备上打开 pkpass

ios - 关闭 View Controller 时我需要自定义 segue

swift - 我一遍又一遍地使用相同的代码块。我如何巩固它?

ios - 我们可以将数据从表格单元格传递到都是 xib 文件的表格 View 吗?

android - 不同应用中的相同 SKU (Google Play)

ios - 请求facebook图片时错误码2500

swift - 在 Swift 中引用环境变量

android - 使用 Google Play 应用内结算的一次性购买的时间试用

android - 这是放置应用内购买成功通知的正确位置吗?

iphone - UIView 应该有多个 UITableViews 作为 subview