From b41d829edda7d3444522fdcf4de52db3f3a8b0da Mon Sep 17 00:00:00 2001 From: BreX900 Date: Thu, 14 Sep 2023 22:46:39 +0200 Subject: [PATCH] fix(ios): Executed fetch token and more actions on main thread --- .../lib/src/generators/swift_api_builder.dart | 12 ++++---- stripe_terminal/CHANGELOG.md | 3 ++ .../stripeterminal/api/StripeTerminalApi.kt | 8 +++--- .../ios/Runner.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- stripe_terminal/example/pubspec.lock | 28 +++++++++---------- .../ios/Classes/Api/StripeTerminalApi.swift | 20 +++++++------ .../ios/Classes/Api/ToApiExtensions.swift | 4 +-- .../Plugin/TerminalDelegatePlugin.swift | 14 +++++++--- .../stripe_terminal_platform.api.dart | 12 ++++---- stripe_terminal/pubspec.yaml | 2 +- 11 files changed, 60 insertions(+), 47 deletions(-) diff --git a/one_for_all_generator/lib/src/generators/swift_api_builder.dart b/one_for_all_generator/lib/src/generators/swift_api_builder.dart index cc74794..7312111 100644 --- a/one_for_all_generator/lib/src/generators/swift_api_builder.dart +++ b/one_for_all_generator/lib/src/generators/swift_api_builder.dart @@ -391,11 +391,13 @@ channel = FlutterMethodChannel( channel.invokeMethod("${handler.channelName(e)}", arguments: [$parameters])''', MethodApiType.async => ''' return try await withCheckedThrowingContinuation { continuation in - channel.invokeMethod("${handler.channelName(e)}", arguments: [$parameters]) { result in - if let result = result as? FlutterError { - continuation.resume(throwing: PlatformError(result.code, result.message, result.details)) - } else { - continuation.resume(returning: ${returnType is VoidType ? '()' : codecs.encodeDeserialization(returnType, 'result')}) + DispatchQueue.main.async { + self.channel.invokeMethod("${handler.channelName(e)}", arguments: [$parameters]) { result in + if let result = result as? FlutterError { + continuation.resume(throwing: PlatformError(result.code, result.message, result.details)) + } else { + continuation.resume(returning: ${returnType is VoidType ? '()' : codecs.encodeDeserialization(returnType, 'result')}) + } } } }''', diff --git a/stripe_terminal/CHANGELOG.md b/stripe_terminal/CHANGELOG.md index de3a629..b578fd7 100644 --- a/stripe_terminal/CHANGELOG.md +++ b/stripe_terminal/CHANGELOG.md @@ -1,4 +1,7 @@ +## 2.1.2 +- fix(ios): Executed fetch token and more actions on main thread + ## 2.1.0 - docs: Documented readers (methods, classes) and payment intents (methods) - feat: added `Readers.batteryStatus` field diff --git a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/api/StripeTerminalApi.kt b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/api/StripeTerminalApi.kt index 659b090..865e6fd 100644 --- a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/api/StripeTerminalApi.kt +++ b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/api/StripeTerminalApi.kt @@ -856,23 +856,23 @@ enum class PaymentStatusApi { data class ReaderApi( val locationStatus: LocationStatusApi?, - val batteryLevel: Double, val deviceType: DeviceTypeApi?, val simulated: Boolean, - val availableUpdate: Boolean, val locationId: String?, val serialNumber: String, + val availableUpdate: Boolean, + val batteryLevel: Double, val label: String?, ) { fun serialize(): List { return listOf( locationStatus?.ordinal, - batteryLevel, deviceType?.ordinal, simulated, - availableUpdate, locationId, serialNumber, + availableUpdate, + batteryLevel, label, ) } diff --git a/stripe_terminal/example/ios/Runner.xcodeproj/project.pbxproj b/stripe_terminal/example/ios/Runner.xcodeproj/project.pbxproj index 063b441..5734a5f 100644 --- a/stripe_terminal/example/ios/Runner.xcodeproj/project.pbxproj +++ b/stripe_terminal/example/ios/Runner.xcodeproj/project.pbxproj @@ -214,7 +214,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1300; + LastUpgradeCheck = 1430; ORGANIZATIONNAME = ""; TargetAttributes = { 331C8080294A63A400263BE5 = { diff --git a/stripe_terminal/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/stripe_terminal/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index e42adcb..87131a0 100644 --- a/stripe_terminal/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/stripe_terminal/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ =3.0.0 <4.0.0" + dart: ">=3.1.0-185.0.dev <4.0.0" flutter: ">=3.10.0" diff --git a/stripe_terminal/ios/Classes/Api/StripeTerminalApi.swift b/stripe_terminal/ios/Classes/Api/StripeTerminalApi.swift index d294874..a4ef057 100644 --- a/stripe_terminal/ios/Classes/Api/StripeTerminalApi.swift +++ b/stripe_terminal/ios/Classes/Api/StripeTerminalApi.swift @@ -480,11 +480,13 @@ class StripeTerminalHandlersApi { func requestConnectionToken() async throws -> String { return try await withCheckedThrowingContinuation { continuation in - channel.invokeMethod("_onRequestConnectionToken", arguments: []) { result in - if let result = result as? FlutterError { - continuation.resume(throwing: PlatformError(result.code, result.message, result.details)) - } else { - continuation.resume(returning: result as! String) + DispatchQueue.main.async { + self.channel.invokeMethod("_onRequestConnectionToken", arguments: []) { result in + if let result = result as? FlutterError { + continuation.resume(throwing: PlatformError(result.code, result.message, result.details)) + } else { + continuation.resume(returning: result as! String) + } } } } @@ -924,23 +926,23 @@ enum PaymentStatusApi: Int { struct ReaderApi { let locationStatus: LocationStatusApi? - let batteryLevel: Double let deviceType: DeviceTypeApi? let simulated: Bool - let availableUpdate: Bool let locationId: String? let serialNumber: String + let availableUpdate: Bool + let batteryLevel: Double let label: String? func serialize() -> [Any?] { return [ locationStatus?.rawValue, - batteryLevel, deviceType?.rawValue, simulated, - availableUpdate, locationId, serialNumber, + availableUpdate, + batteryLevel, label, ] } diff --git a/stripe_terminal/ios/Classes/Api/ToApiExtensions.swift b/stripe_terminal/ios/Classes/Api/ToApiExtensions.swift index b4947af..c581cc2 100644 --- a/stripe_terminal/ios/Classes/Api/ToApiExtensions.swift +++ b/stripe_terminal/ios/Classes/Api/ToApiExtensions.swift @@ -17,12 +17,12 @@ extension Reader { func toApi() -> ReaderApi { return ReaderApi( locationStatus: locationStatus.toApi(), - batteryLevel: batteryLevel?.doubleValue ?? -1.0, deviceType: deviceType.toApi(), simulated: simulated, - availableUpdate: availableUpdate != nil, locationId: locationId, serialNumber: serialNumber, + availableUpdate: availableUpdate != nil, + batteryLevel: batteryLevel?.doubleValue ?? -1.0, label: label ) } diff --git a/stripe_terminal/ios/Classes/Plugin/TerminalDelegatePlugin.swift b/stripe_terminal/ios/Classes/Plugin/TerminalDelegatePlugin.swift index e268682..3cf0a06 100644 --- a/stripe_terminal/ios/Classes/Plugin/TerminalDelegatePlugin.swift +++ b/stripe_terminal/ios/Classes/Plugin/TerminalDelegatePlugin.swift @@ -9,18 +9,24 @@ class TerminalDelegatePlugin: NSObject, ConnectionTokenProvider, TerminalDelegat } public func fetchConnectionToken() async throws -> String { - return try await handlers.requestConnectionToken() + return try await self.handlers.requestConnectionToken() } public func terminal(_: Terminal, didReportUnexpectedReaderDisconnect reader: Reader) { - handlers.unexpectedReaderDisconnect(reader: reader.toApi()) + DispatchQueue.main.async { + self.handlers.unexpectedReaderDisconnect(reader: reader.toApi()) + } } public func terminal(_: Terminal, didChangePaymentStatus status: PaymentStatus) { - handlers.paymentStatusChange(paymentStatus: status.toApi()) + DispatchQueue.main.async { + self.handlers.paymentStatusChange(paymentStatus: status.toApi()) + } } public func terminal(_: Terminal, didChangeConnectionStatus status: ConnectionStatus) { - handlers.connectionStatusChange(connectionStatus: status.toApi()) + DispatchQueue.main.async { + self.handlers.connectionStatusChange(connectionStatus: status.toApi()) + } } } diff --git a/stripe_terminal/lib/src/platform/stripe_terminal_platform.api.dart b/stripe_terminal/lib/src/platform/stripe_terminal_platform.api.dart index bc77499..1ec61c6 100644 --- a/stripe_terminal/lib/src/platform/stripe_terminal_platform.api.dart +++ b/stripe_terminal/lib/src/platform/stripe_terminal_platform.api.dart @@ -634,13 +634,13 @@ Reader _$deserializeReader(List serialized) => Reader( locationStatus: serialized[0] != null ? LocationStatus.values[serialized[0] as int] : null, - batteryLevel: serialized[1] as double, deviceType: - serialized[2] != null ? DeviceType.values[serialized[2] as int] : null, - simulated: serialized[3] as bool, - availableUpdate: serialized[4] as bool, - locationId: serialized[5] as String?, - serialNumber: serialized[6] as String, + serialized[1] != null ? DeviceType.values[serialized[1] as int] : null, + simulated: serialized[2] as bool, + locationId: serialized[3] as String?, + serialNumber: serialized[4] as String, + availableUpdate: serialized[5] as bool, + batteryLevel: serialized[6] as double, label: serialized[7] as String?); ReaderSoftwareUpdate _$deserializeReaderSoftwareUpdate( List serialized) => diff --git a/stripe_terminal/pubspec.yaml b/stripe_terminal/pubspec.yaml index 6a396b4..b8954b0 100644 --- a/stripe_terminal/pubspec.yaml +++ b/stripe_terminal/pubspec.yaml @@ -1,6 +1,6 @@ name: mek_stripe_terminal description: A StripeTerminal plugin to discover readers, connect to them and process payments. -version: 2.1.0 +version: 2.1.2 repository: https://github.com/BreX900/mek-packages/tree/main/stripe_terminal topics: - stripe-terminal