首页 > 解决方案 > 更改应用程序购买价格后应用程序崩溃,但在从 Xcode 调试到设备和模拟器时有效

问题描述

几周前我刚刚完成将我的应用程序上传到应用商店,但就在昨天,我刚刚从 App Store Connect 更改了非消耗性产品的价格。

我已经从模拟器再次尝试了我的应用程序,并从 Xcode 调试到真实设备,一切正常,价格也更改为我在应用商店连接中更改的价格。

但是当我从 App Store 下载应用程序并尝试打开产品页面时,它会崩溃。我不知道为什么会发生这种情况,我没有更改我的应用程序中的任何代码。我什至将我的应用程序重新提交到 App Store,但结果仍然相同,它在显示产品价格的页面上崩溃。

至于获取产品并显示价格的代码,这是我的代码:

enum Product: String, CaseIterable {
    case membershippayment = "com.myproducts"
}

func fetchProducts() {
    
    let request = SKProductsRequest(productIdentifiers: Set(Product.allCases.compactMap({ $0.rawValue })))
    request.delegate = self
    request.start()
    
}


func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
     
    DispatchQueue.main.async {
        self.models = response.products
         
        
        let product = response.products.first 
        let price = product!.price
        let int: Int = Int(truncating: price)
        let intFormatted = int.formattedWithSeparator
        
        self.txtPrice.text = "Rp. \(intFormatted)"
        self.Price_Payment = "\(price)"
    }
}

编辑:只需将行更改 let price = product!.pricelet price = product?.price ?? 0

并将应用程序重新上传到应用程序商店,看起来当应用程序上传到应用程序商店时价格返回 nil 值,因为显示的文本显示“0”为什么会发生这种情况,我需要在应用程序商店中做其他事情吗连接?我不知道这是否重要,但应用内购买产品的状态为“缺少合规性”,是不是因为这个?如果是,我该如何解决?

标签: swiftstorekit

解决方案


在我看来,您没有在构建 gradle 中更改您的应用程序版本。每次更新应用程序都应该添加 1 个数字

Gradle 脚本 -> build.gradle (Module: ...) -> 查找:

android { compileSdkVersion 30 buildToolsVersion "30.0.3"

defaultConfig {
    applicationId "com.example.barcodescanner3"
    minSdkVersion 19
    targetSdkVersion 30
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

更改 versionCode 和 versionName。版本名称可以是 (1.1,1.2,1.3) 但版本代码只允许整数 (1,2,3)

希望有帮助,对不起我的英语不好


推荐阅读