diff --git a/.github/workflows/ci-example-ios.yml b/.github/workflows/ci-example-ios.yml index 3a26ec509..f7358e2ec 100644 --- a/.github/workflows/ci-example-ios.yml +++ b/.github/workflows/ci-example-ios.yml @@ -19,7 +19,7 @@ on: jobs: build_ios_example: - runs-on: macos-latest + runs-on: macos-14 steps: - name: Checkout repository @@ -48,6 +48,9 @@ jobs: bundler-cache: true ruby-version: '2.7' + - name: Install SwiftLint + run: brew install swiftlint + - name: SwiftLint run: swiftlint lint --fix --format --path ios/*.swift --config .swiftlint.yml diff --git a/ios/IapUtils.swift b/ios/IapUtils.swift index 47cc1a05f..93deb2ace 100644 --- a/ios/IapUtils.swift +++ b/ios/IapUtils.swift @@ -7,6 +7,7 @@ import Foundation import StoreKit +import React public func debugMessage(_ object: Any...) { #if DEBUG @@ -30,8 +31,10 @@ func checkVerified(_ result: VerificationResult) throws -> T { } @available(iOS 15.0, *) -func currentWindow() -> UIWindow? { - return UIApplication.shared.connectedScenes - .flatMap { ($0 as? UIWindowScene)?.windows ?? [] } - .last { $0.isKeyWindow } +func currentWindow() async -> UIWindow? { + await withCheckedContinuation { continuation in + DispatchQueue.main.async { + continuation.resume(returning: RCTKeyWindow()) + } + } } diff --git a/ios/RNIapIosSk2.swift b/ios/RNIapIosSk2.swift index 22d402a9f..67cb77f6c 100644 --- a/ios/RNIapIosSk2.swift +++ b/ios/RNIapIosSk2.swift @@ -961,22 +961,20 @@ class RNIapIosSk2iOS15: Sk2Delegate { reject: @escaping RCTPromiseRejectBlock = { _, _, _ in } ) { #if !os(tvOS) - DispatchQueue.main.async { - guard let scene = currentWindow()?.windowScene as? UIWindowScene, + Task { + guard let scene = await currentWindow()?.windowScene as? UIWindowScene, !ProcessInfo.processInfo.isiOSAppOnMac else { return } - - Task { - do { - try await AppStore.showManageSubscriptions(in: scene) - } catch { - print("Error:(error)") - } + + do { + try await AppStore.showManageSubscriptions(in: scene) + } catch { + print("Error:(error)") } - - resolve(nil) } + + resolve(nil) #else reject(IapErrors.E_USER_CANCELLED.rawValue, "This method is not available on tvOS", nil) #endif @@ -1013,9 +1011,8 @@ class RNIapIosSk2iOS15: Sk2Delegate { } } - let window = currentWindow() - Task { + let window = await currentWindow() if let windowScene = await window?.windowScene { if let product = await productStore.getProduct(productID: sku) { if let result = await product.latestTransaction {