RevenueCat / purchases-flutter

Flutter plugin for in-app purchases and subscriptions. Supports iOS, macOS and Android.
https://www.revenuecat.com/
MIT License
607 stars 168 forks source link

Purchases has not been configured [Fatal error][iOS release + testflight] #1121

Closed MiroLiebschner closed 1 month ago

MiroLiebschner commented 2 months ago

Environment

! Doctor found issues in 1 category.`

iOS 17.5.1 (iPhone Pro Max) and multiple other iOS devices

In release mode and on testflight. Only sometimes (race-condition?).

`// // FatalErrorUtil.swift // PurchasesHybridCommon // // Created by Andrés Boedo on 4/20/22. // Copyright © 2022 RevenueCat. All rights reserved. //

import Foundation

enum FatalErrorUtil {

fileprivate static var fatalErrorClosure: (String, StaticString, UInt) -> Never = defaultFatalErrorClosure

private static let defaultFatalErrorClosure = { Swift.fatalError($0, file: $1, line: $2) }

static func replaceFatalError(closure: @escaping (String, StaticString, UInt) -> Never) {
    fatalErrorClosure = closure
}

static func restoreFatalError() {
    fatalErrorClosure = defaultFatalErrorClosure
}

}

func fatalError(_ message: @autoclosure () -> String = "", file: StaticString = #fileID, line: UInt = #line) -> Never { FatalErrorUtil.fatalErrorClosure(message(), file, line) }

`

error message: Thread 1: Fatal error: Purchases has not been configured. Please configure the SDK before calling this method

Describe the bug

The app crashes with a fatal error. This happens only on iOS and only in Release mode or on Testflight (debug mode runs fine).

RCGitBot commented 2 months ago

👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!

aboedo commented 2 months ago

Hi 👋 This error occurs when methods from the SDK have been called before the SDK has been configured. I'd recommend examining the places where this happens to ensure that the SDK is configured before it's in use.

In particular, I'd recommend configuring the SDK as early as possible in your app's lifetime to prevent running into this kind of issue.

mshmoustafa commented 1 month ago

Hi @MiroLiebschner, since this issue hasn't been updated for a while and Andy's reply is the correct solution here, I'm going to close it. If you're still having this issue or you have additional information to share, please feel free to reopen it and mention either Andy or myself.