priceLocale在访问时抛出EXC_BREAKPOINT

Nic*_*voz 5 ios skproduct swift swiftystorekit

我们在我们的应用程序上使用介绍价格。而且,我们只有两个QA设备(法国App Store上的iPhone 6S(11.4.1))中的一个问题可以重现。另一个是iPhone 7(法语应用商店中为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
    }
}
Run Code Online (Sandbox Code Playgroud)

像这样使用:

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
}
}
Run Code Online (Sandbox Code Playgroud)

调试时,我们发现priceLocale负责引发EXC_BREAKPOINT

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

小智 -1

尝试这个:

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"
}
Run Code Online (Sandbox Code Playgroud)

将 SKProduct() 替换为您的产品。

就我而言,当在产品初始化之前访问函数时,就会发生这种情况。