简体   繁体   English

Mac Catalyst 上的应用内购买不起作用

[英]In App Purchase on Mac Catalyst Not Working

In app purchases work fine for my iOS side of things.应用内购买适用于我的 iOS 方面。 The data from StoreKit is populated as it should. StoreKit 中的数据按应有的方式填充。 The same code doesn't work on the Mac Catalyst version of the project.相同的代码不适用于项目的 Mac Catalyst 版本。 I have even created a listing for my Mac app on App Store connect with different bundle identifiers for the in app purchases.我什至在 App Store 上为我的 Mac 应用创建了一个列表,并为应用内购买提供了不同的捆绑标识符。 I have a print function that returns what product StoreKit found, it works well on iOS, but results with nothing when using Mac Catalyst.我有一个打印 function 返回 StoreKit 找到的产品,它在 iOS 上运行良好,但在使用 Mac Catalyst 时没有任何结果。

Here is what I have done:这是我所做的:

  1. Make sure that In App purchases has been added in the capabilities section.确保在功能部分中添加了应用内购买。
  2. Make sure the Store Kit framework has been imported.确保已导入 Store Kit 框架。
  3. Make sure the bundle identifiers are correct.确保捆绑包标识符正确。
  4. Make sure all agreements are filled out.确保填写所有协议。
  5. I am signed out of the Mac App Store.我已退出 Mac App Store。

Code that works on iOS but not on MacOS:适用于 iOS 但不适用于 MacOS 的代码:

    override func viewDidLoad() {
    SKPaymentQueue.default().add(self)


    let productIds: Set<String> = ["..."]
    var request = SKProductsRequest(productIdentifiers: productIds)
    request.delegate = self
    request.start()
}

  func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
    print("Loaded")

    for product in response.products {
        print("What came: \(product.productIdentifier) \(product.localizedTitle) \(product.price.floatValue)")}

The iOS app will return with the Product Identifier, Title and Price. iOS 应用程序将返回产品标识符、标题和价格。 The Mac app will return with nothing at all. Mac 应用程序将一无所有地返回。

I found the problem.我发现了问题。 I had not created a strong reference to my product request.我没有创建对我的产品请求的强引用。

This line of code fixed my issue:这行代码解决了我的问题:

var request: SKProductsRequest!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM