Skip to content

Commit

Permalink
Fix crash in withCheckedContinuation on iOS 18.0 (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
leoMehlig authored Sep 25, 2024
1 parent fe2d323 commit cf33276
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Sources/ConfigCat/ConfigCatClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ public final class ConfigCatClient: NSObject, ConfigCatClientProtocol {
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@discardableResult
public func waitForReady() async -> ClientReadyState {
await withCheckedContinuation { continuation in
// withCheckedContinuation sometimes crashes on iOS 18.0. See https://github.com/RevenueCat/purchases-ios/pull/4286
await withUnsafeContinuation { continuation in
guard let configService = self.configService else {
continuation.resume(returning: .hasLocalOverrideFlagDataOnly)
return
Expand Down
18 changes: 9 additions & 9 deletions Sources/ConfigCat/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ extension ConfigCatClient {
#if compiler(>=5.5) && canImport(_Concurrency)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public func getValue<Value>(for key: String, defaultValue: Value, user: ConfigCatUser? = nil) async -> Value {
await withCheckedContinuation { continuation in
await withUnsafeContinuation { continuation in
getValue(for: key, defaultValue: defaultValue, user: user) { value in
continuation.resume(returning: value)
}
Expand All @@ -71,7 +71,7 @@ extension ConfigCatClient {

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public func getAnyValue(for key: String, defaultValue: Any?, user: ConfigCatUser? = nil) async -> Any? {
await withCheckedContinuation { continuation in
await withUnsafeContinuation { continuation in
getValue(for: key, defaultValue: defaultValue, user: user) { value in
continuation.resume(returning: value)
}
Expand All @@ -80,7 +80,7 @@ extension ConfigCatClient {

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public func getValueDetails<Value>(for key: String, defaultValue: Value, user: ConfigCatUser? = nil) async -> TypedEvaluationDetails<Value> {
await withCheckedContinuation { continuation in
await withUnsafeContinuation { continuation in
getValueDetails(for: key, defaultValue: defaultValue, user: user) { details in
continuation.resume(returning: details)
}
Expand All @@ -89,7 +89,7 @@ extension ConfigCatClient {

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public func getAnyValueDetails(for key: String, defaultValue: Any?, user: ConfigCatUser? = nil) async -> TypedEvaluationDetails<Any?> {
await withCheckedContinuation { continuation in
await withUnsafeContinuation { continuation in
getValueDetails(for: key, defaultValue: defaultValue, user: user) { details in
continuation.resume(returning: details)
}
Expand All @@ -98,7 +98,7 @@ extension ConfigCatClient {

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public func getAllValueDetails(user: ConfigCatUser? = nil) async -> [EvaluationDetails] {
await withCheckedContinuation { continuation in
await withUnsafeContinuation { continuation in
getAllValueDetails(user: user) { details in
continuation.resume(returning: details)
}
Expand All @@ -107,7 +107,7 @@ extension ConfigCatClient {

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public func getAllKeys() async -> [String] {
await withCheckedContinuation { continuation in
await withUnsafeContinuation { continuation in
getAllKeys { keys in
continuation.resume(returning: keys)
}
Expand All @@ -116,7 +116,7 @@ extension ConfigCatClient {

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public func getKeyAndValue(for variationId: String) async -> KeyValue? {
await withCheckedContinuation { continuation in
await withUnsafeContinuation { continuation in
getKeyAndValue(for: variationId) { value in
continuation.resume(returning: value)
}
Expand All @@ -125,7 +125,7 @@ extension ConfigCatClient {

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public func getAllValues(user: ConfigCatUser? = nil) async -> [String: Any] {
await withCheckedContinuation { continuation in
await withUnsafeContinuation { continuation in
getAllValues(user: user) { values in
continuation.resume(returning: values)
}
Expand All @@ -135,7 +135,7 @@ extension ConfigCatClient {
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@discardableResult
public func forceRefresh() async -> RefreshResult {
await withCheckedContinuation { continuation in
await withUnsafeContinuation { continuation in
forceRefresh { result in
continuation.resume(returning: result)
}
Expand Down

0 comments on commit cf33276

Please sign in to comment.