Nicolas Charvoz
Nicolas Charvoz

Reputation: 1509

priceLocale throw an EXC_BREAKPOINT when accessed

We are using Introductory Prices on our app. And we have an issue only reproducible on one of our two QA devices which is an iPhone 6S (11.4.1) on the French App Store. The other is an iPhone 7 (12.0 with French App Store) and the app is not crashing.

We are using this extension based on the SKProduct extension provided by SwiftyStoreKit :

@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
    }
}

Used like this :

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
}
}

When debugging we found that priceLocale is responsible for throwing the EXC_BREAKPOINT.

EDIT Could be linked to this : https://bugs.swift.org/browse/SR-7922?attachmentOrder=desc but it's strange that it would work on our iPhone 7 and not on the iPhone 6s

Upvotes: 12

Views: 770

Answers (1)

ShionPro
ShionPro

Reputation: 1

Try this:

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"
}

Replace SKProduct() with your product.

In my case, this occurs when the function accessed before the product initialized.

Upvotes: -1

Related Questions