ios - priceLocale 在访问时抛出 EXC_BREAKPOINT

标签 ios swift skproduct swiftystorekit

我们在我们的应用程序上使用介绍性价格。我们有一个问题只能在我们的两个 QA 设备之一上重现,即法国 App Store 上的 iPhone 6S (11.4.1)。另一个是 iPhone 7(带有法语 App Store 的 12.0),该应用程序没有崩溃。

我们正在使用这个基于 SwiftyStoreKit 提供的 SKProduct 扩展的扩展:

@available(iOS 11.2, *)
public extension SKProductDiscount {

    public var localizedPrice: String? {
        return priceFormatter(locale: priceLocale).string(from: price)
    }

    private func priceFormatter(locale: Locale) -> NumberFormatter {
        let formatter = NumberFormatter()
        formatter.locale = locale
        formatter.numberStyle = .currency
        return formatter
    }
}

像这样使用:
func updateWith(storeProducts: Set<SKProduct>) {
guard
    let selfStoreInfo = storeProducts.filter({ $0.productIdentifier == self.id }).first else {
        Logger.warn(message: "Subscription \(self.id) not found on store", .inAppPurchase)
    return
}

if #available(iOS 11.2, *) {
    if let promo = selfStoreInfo.introductoryPrice {
        promotionId = selfStoreInfo.productIdentifier
        price = promo.localizedPrice
        originalPrice = selfStoreInfo.localizedPrice
    } else {
        price = selfStoreInfo.localizedPrice
    }
} else {
    price = selfStoreInfo.localizedPrice
}
}

调试时我们发现priceLocale负责抛出EXC_BREAKPOINT .

编辑 可以链接到这个:https://bugs.swift.org/browse/SR-7922?attachmentOrder=desc但奇怪的是它可以在我们的 iPhone 7 上运行,而不是在 iPhone 6s 上

最佳答案

尝试这个:

DispatchQueue.global(qos: .default).async {
while true {
    if !SKProduct().productIdentifier.isEmpty {
        if let productPriceString: String = SC.storeProduct.localizedPrice {
            DispatchQueue.main.async {
                print(productPriceString)
            }
        }
        break
    }
    // Some wait process like using "semaphore"
}
将 SKProduct() 替换为您的产品。
就我而言,这发生在产品初始化之前访问的函数时。

关于ios - priceLocale 在访问时抛出 EXC_BREAKPOINT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53169358/

相关文章:

iOS 应用商店唯一的应用名称?

ios - longPress 时启用 UIPanGestureRecognizer

swift - iOS UIImageView 不自动刷新

ios - 应用内购买沙盒 - 持续提示 Apple 登录?

swift - Swift 中 SKProduct 的 NSCoding 错误

ios - SKProductStorePromotionController 更新方法不起作用

ios - QuartzCore 动画形状?

iOS打开PDF

php - uploadTask 方法不起作用 URLSession Swift 3

ios - 在 Swift/IOS 中获取实际 View 大小