应用内购买不在测试飞行中

发布于 2025-02-11 12:02:28 字数 2458 浏览 2 评论 0原文

我的应用程序被苹果拒绝了,因为他们无法让我的IAP上班。我只在Xcode上进行测试,一切似乎都很好(我不知道通过测试飞行测试)。从那以后,我一直在测试Flight,而IAP对此不起作用。

谁能就我出错的地方提供任何建议?我在签名&中添加了“应用内购买”。功能。我已经在测试飞行中测试了两个Storekit配置,将“无”设置为“无”,也将“ configuration.storekit”设置为。

我在App Store Connect上的IAP具有“准备提交”状态。

import StoreKit

class Menu: SKScene, SKProductsRequestDelegate, SKPaymentTransactionObserver {
    
    enum Product: String, CaseIterable {
        case premium = "[my IAP identifier]"
    }
    
    func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
        if let oProduct = response.products.first {
            print("Product is available")
            self.purchase(aproduct: oProduct)
        } else {
            print("Product is not available")
        }
    }
    
    func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
        for transaction in transactions {
            switch transaction.transactionState {
            case .purchased:
                SKPaymentQueue.default().finishTransaction(transaction)
                print("Purchased")
                purchasedPremium = true
                
                userDefaults.set(true, forKey: "purchasedPremium")
                
                var transition:SKTransition = SKTransition.fade(withDuration: 1)
                var scene:SKScene = Menu(size: self.size)
                self.view?.presentScene(scene, transition: transition)
                
            case .failed:
                SKPaymentQueue.default().finishTransaction(transaction)
                print("Failed")
            case .restored:
                print("Restored")
            case .deferred:
                print("Deferred")
            default:
                break
            }
        }
    }
    
    func purchase(aproduct: SKProduct) {
        let payment = SKPayment(product: aproduct)
        SKPaymentQueue.default().add(self)
        SKPaymentQueue.default().add(payment)
    }

我通过运行此方法触发购买过程:

func buyPremium() {
        if SKPaymentQueue.canMakePayments() {
            let set : Set<String> = [Product.premium.rawValue]
            let productRequest = SKProductsRequest(productIdentifiers: set)
            productRequest.delegate = self
            productRequest.start()
        }
    }

My app was rejected by Apple, as they couldn't get my IAP to work. I'd only been testing through Xcode, and everything seemed to be working fine (I had no idea to test through TestFlight). I've since been testing through TestFlight, and the IAP doesn't work on this.

Can anyone offer any advice on where I'm going wrong? I have added "In-App Purchase" to the Signing & Capabilities. I have tested in TestFlight with both StoreKit Configuration set to "None" and also "Configuration.storekit".

My IAP on App Store Connect has the status “Ready to Submit”.

import StoreKit

class Menu: SKScene, SKProductsRequestDelegate, SKPaymentTransactionObserver {
    
    enum Product: String, CaseIterable {
        case premium = "[my IAP identifier]"
    }
    
    func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
        if let oProduct = response.products.first {
            print("Product is available")
            self.purchase(aproduct: oProduct)
        } else {
            print("Product is not available")
        }
    }
    
    func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
        for transaction in transactions {
            switch transaction.transactionState {
            case .purchased:
                SKPaymentQueue.default().finishTransaction(transaction)
                print("Purchased")
                purchasedPremium = true
                
                userDefaults.set(true, forKey: "purchasedPremium")
                
                var transition:SKTransition = SKTransition.fade(withDuration: 1)
                var scene:SKScene = Menu(size: self.size)
                self.view?.presentScene(scene, transition: transition)
                
            case .failed:
                SKPaymentQueue.default().finishTransaction(transaction)
                print("Failed")
            case .restored:
                print("Restored")
            case .deferred:
                print("Deferred")
            default:
                break
            }
        }
    }
    
    func purchase(aproduct: SKProduct) {
        let payment = SKPayment(product: aproduct)
        SKPaymentQueue.default().add(self)
        SKPaymentQueue.default().add(payment)
    }

I trigger the purchase procedure by running this method:

func buyPremium() {
        if SKPaymentQueue.canMakePayments() {
            let set : Set<String> = [Product.premium.rawValue]
            let productRequest = SKProductsRequest(productIdentifiers: set)
            productRequest.delegate = self
            productRequest.start()
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

像极了他 2025-02-18 12:02:28

您为产品请求和购买实施的流量不正确。

当用户启动购买时,您不应要求产品,并且在检索skproduct时不应启动购买。

您应该采用以下内容:

  • didfinishlaunching“购买经理”中实例化“
  • 购买经理”对象。
    • 将自己设置为付款队列观察者。
    • 检查CanMakePayments
    • 如果true然后请求您的产品
    • 如果您成功检索了产品,请存储skproduct并向您的应用程序视图注明IAP可用
  • 然后,您的视图可以显示/启用购买UI(按钮等)
    • 用户点击购买按钮时,您将获得“购买经理”提交skpayment
    • 一旦购买完成后,请坚持购买状态并刷新您的观点以解锁购买的内容

内容您的队列观察者立即在发布时立即进行,因为在队列中可能需要进行待处理,以供您的应用程序处理。

检查产品可用性和CanMakepayments首先通过确保未向其显示无法使用的购买选项来改善用户体验

The flow you have implemented for your product request and purchase is not correct.

You should not request the product when the user initiates the purchase and you should not initiate the purchase when the SKProduct is retrieved.

You should adopt something like the following:

  • Instantiate a "purchase manager" object in didFinishLaunching
  • The "purchase manager" should:
    • Set itself as the payment queue observer.
    • Check for canMakePayments
    • If true then request your product
    • If you successfully retrieve your product, store the SKProduct and indicate to your app views that IAP is available
  • Your views can then show/enable the purchase UI (button etc)
    • When the user taps the purchase button you get your "purchase manager" to submit the SKPayment
    • Once the purchase is complete, persist the purchase state and refresh your views to unlock the purchased content

It is important that you establish your queue observer immediately on launch as there may be a pending purchase in the queue for your app to process.

Checking for product availability and canMakePayments first improves the user experience by ensuring they are not shown a purchase option that they cannot use

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文