ios - 应用内购买适用于 iPhone 但不适用于 iPad

标签 ios swift in-app-purchase storekit

我在 iOS 上遇到应用内购买问题。我在一款游戏中有 5 项应用内购买,在 iPhone 6 (iOS 8.3) 上测试时,所有这些都完全符合预期。当我在 iPad Air 2 (iOS 8.2) 上进行测试时,所有 IAP 立即失败。还有其他人遇到过这个问题吗?是否有一些我必须添加的特定于 iPad 的代码?

编辑:奇怪的是,将 iPad 更新到 iOS 8.3 解决了这个问题。关于为什么会出现此问题的任何想法?我是否应该将我的应用更改为仅支持 iOS 8.3 及更高版本?

为了测试该应用,我使用了 TestFlight、相同的网络连接和相同的 Apple ID。

我用于应用内购买的代码如下:

func inApp() {
    if (SKPaymentQueue.canMakePayments())
    {
        var productID:NSSet = NSSet(object: product_id);
        var productsRequest:SKProductsRequest = SKProductsRequest(productIdentifiers: productID as Set<NSObject>);
        productsRequest.delegate = self;
        productsRequest.start();
    }else{
        displayAlert()
    }
}

func buyProduct(product: SKProduct){
    var payment = SKPayment(product: product)
    SKPaymentQueue.defaultQueue().addPayment(payment);

}

func productsRequest (request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {
    var count : Int = response.products.count
    if (count>0) {
        var validProducts = response.products
        var validProduct: SKProduct = response.products[0] as! SKProduct
        if (validProduct.productIdentifier == product_id) {
            println(validProduct.localizedTitle)
            println(validProduct.localizedDescription)
            println(validProduct.price)
            buyProduct(validProduct);
        } else {
            println(validProduct.productIdentifier)
        }
    } else {
        displayAlert()
    }
}


func request(request: SKRequest!, didFailWithError error: NSError!) {
    self.displayAlert()
}

func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!)    {
    for transaction:AnyObject in transactions {
        if let trans:SKPaymentTransaction = transaction as? SKPaymentTransaction{
            switch trans.transactionState {
            case .Purchased:
                SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
                if product_id == "com.shv.FrenzyTenLives" {
                    defaults.setInteger(10, forKey: "totalLives")
                } else if product_id == "com.shv.FrenzyFiveLives" {
                    defaults.setInteger(5, forKey: "totalLives")
                } else if product_id == "com.shv.FrenzyInfiniteLives" {
                    defaults.setBool(true, forKey: "infiniteLives")
                } else if product_id == "com.shv.FrenzyShield" {
                    defaults.setInteger(5, forKey: "shieldValue")
                } else if product_id == "com.shv.FrenzyRemoveAds" {
                    defaults.setBool(true, forKey: "adsRemoved")
                    adBanner.hidden = true
                }
                break;
            case .Failed:
                SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
                self.displayAlert()
                break;
            case .Restored:
                SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
                if product_id == "com.shv.FrenzyTenLives" {
                    defaults.setInteger(10, forKey: "totalLives")
                } else if product_id == "com.shv.FrenzyFiveLives" {
                    defaults.setInteger(5, forKey: "totalLives")
                } else if product_id == "com.shv.FrenzyInfiniteLives" {
                    defaults.setBool(true, forKey: "infiniteLives")
                } else if product_id == "com.shv.FrenzyRemoveAds" {
                    defaults.setBool(true, forKey: "adsRemoved")
                    adBanner.hidden = true
                }
                break;
            default:
                break;
            }
        }
    }
}

最佳答案

通常,当一台设备无法执行应用购买时,这是一种受限制的设置。

如果您已选中并禁用该限制或所有限制 - 您通常可以通过完全退出 App Store 并关闭设备来解决此问题。当它干净地启动时,您可以再次登录。登录时,请务必购买一些东西(本周免费歌曲、免费应用程序甚至付费应用程序)以通过验证问题。完成后,重新检查 IAP(应用内购买)以确保一切正常。

作为最后的手段,您可能需要联系 Apple 支持以获取 Apple ID - 但大多数情况下您无需他们的帮助即可解决此问题。

您应该检查以下事项。

确保您可以对以下每个问题回答"is":

  • 您是否为您的 App ID 启用了应用内购买?
  • 您是否检查过您的产品是否已获准销售?
  • 您项目的 .plist Bundle ID 是否与您的 App ID 匹配?
  • 您是否为新 App ID 生成并安装了新的配置文件?
  • 您是否已将您的项目配置为使用这个新的配置文件进行代码签名?
  • 您在发出 SKProductRequest 时是否使用了完整的产品 ID?
  • 将产品添加到 iTunes Connect 后,您是否已经等了几个小时?
  • 您是否尝试过从您的设备中删除该应用并重新安装?
  • 您的设备是否已越狱?如果是这样,您需要恢复越狱以使 IAP 正常工作。

如果您对这些问题中的任何一个回答“否”,那就是您的问题。

您应该访问以下链接,您肯定会得到解决方案。

https://www.innofied.com/in-app-purchase-working-ios-solution/

关于ios - 应用内购买适用于 iPhone 但不适用于 iPad,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29707305/

相关文章:

iOS 应用内购买拒绝 : Missing IAPs

ios - UILocalNotification.alertBody 的格式化文本

ios - Xcode CI 和 cocoapods 私有(private)仓库

objective-c - 如何在屏幕截图上忽略我的应用程序窗口? ( swift 2.0)

ios - Swift 2.1 核心数据 - 使用 setValue() 更新图像记录

ios - 缺少IAP-尽管IAP正在“等待审核”

ios - 导航至谷歌地图 回拨

iOS:我可以告诉 UIView 放弃它的 CALayer 吗?

ios - 在自定义类中呈现 UIDocumentInteractionController 的问题

android - 如何在应用计费 API V3 中使用 Google 的随机数