【问题标题】:priceLocale throw an EXC_BREAKPOINT when accessedpriceLocale 在访问时抛出 EXC_BREAKPOINT
【发布时间】:2019-04-09 16:42:14
【问题描述】:

我们在我们的应用程序上使用介绍性价格。我们有一个问题只能在我们的两个 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 上

【问题讨论】:

  • 您找到解决方法了吗?我在我的代码中看到了同样的事情。
  • 我也遇到了同样的问题

标签: ios swift skproduct swiftystorekit


【解决方案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"
}

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

在我的例子中,这发生在产品初始化之前访问的函数时。

【讨论】:

  • 我很抱歉我的错误。 SC 是我自己的 StoreKit 经理级,所以请用您的产品替换“SC.storeProduct”。
  • 请添加更多详细信息以扩展您的答案,例如工作代码或文档引用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-06
  • 1970-01-01
  • 1970-01-01
  • 2011-12-30
  • 1970-01-01
相关资源
最近更新 更多