priceLocale throw an EXC_BREAKPOINT when accessed
Asked Answered
O

1

12

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

Osiris answered 6/11, 2018 at 9:47 Comment(2)
Did you ever find a fix for this? I am seeing the same thing in my code.Eckstein
i'm facing the same problemVacuous
P
-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.

Pinpoint answered 8/9, 2021 at 9:54 Comment(2)
I'm sorry for my mistake. SC is my own StoreKit manager-class so please replace "SC.storeProduct" with your product.Pinpoint
Please add further details to expand on your answer, such as working code or documentation citations.Iover

© 2022 - 2024 — McMap. All rights reserved.