From 387731d556b767c399d3faa981423e80288ef99d Mon Sep 17 00:00:00 2001 From: crow Date: Fri, 25 Oct 2024 10:19:34 -0700 Subject: [PATCH 1/5] Fix event streams on android and ios --- .../com/airship/flutter/AirshipPlugin.kt | 33 ++++++++++++----- ios/Classes/SwiftAirshipPlugin.swift | 35 ++++++++++++++++--- 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/android/src/main/kotlin/com/airship/flutter/AirshipPlugin.kt b/android/src/main/kotlin/com/airship/flutter/AirshipPlugin.kt index affaa021..4d61fec6 100644 --- a/android/src/main/kotlin/com/airship/flutter/AirshipPlugin.kt +++ b/android/src/main/kotlin/com/airship/flutter/AirshipPlugin.kt @@ -29,6 +29,13 @@ import kotlinx.coroutines.* import java.util.concurrent.locks.ReentrantLock import kotlin.concurrent.withLock import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.filter +import kotlinx.coroutines.flow.filterNotNull +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.map class AirshipPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { @@ -456,25 +463,26 @@ class AirshipPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { override fun onDetachedFromActivity() { mainActivity = null } + class AirshipEventStreamHandler : EventChannel.StreamHandler { - private var eventSink: EventChannel.EventSink? = null + val eventFlow: StateFlow get() = _eventSink + + private var _eventSink: MutableStateFlow = MutableStateFlow(null) override fun onListen(arguments: Any?, events: EventChannel.EventSink?) { - this.eventSink = events + this._eventSink.value = events } override fun onCancel(arguments: Any?) { - this.eventSink = null + this._eventSink.value = null } fun notify(event: Any): Boolean { - val sink = eventSink - return if (sink != null) { - sink.success(event) + return _eventSink.value?.let { + it.success(event) + true - } else { - false - } + } ?: false } } class AirshipEventStream( @@ -494,7 +502,14 @@ class AirshipPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { lock.withLock { handlers.add(handler) } + + coroutineScope.launch { + handler.eventFlow.filterNotNull().collect { + processPendingEvents() + } + } } + fun processPendingEvents() { EventEmitter.shared().processPending(eventTypes) { event -> val unwrappedEvent = event.body.unwrap() diff --git a/ios/Classes/SwiftAirshipPlugin.swift b/ios/Classes/SwiftAirshipPlugin.swift index 60c2899f..51e59caf 100644 --- a/ios/Classes/SwiftAirshipPlugin.swift +++ b/ios/Classes/SwiftAirshipPlugin.swift @@ -2,7 +2,7 @@ import Flutter import UIKit import AirshipKit import AirshipFrameworkProxy -import Combine +import Combine public class SwiftAirshipPlugin: NSObject, FlutterPlugin { private static let eventNames: [AirshipProxyEventType: String] = [ @@ -29,8 +29,10 @@ public class SwiftAirshipPlugin: NSObject, FlutterPlugin { private var subscriptions = Set() + static let shared = SwiftAirshipPlugin() + public static func register(with registrar: FlutterPluginRegistrar) { - SwiftAirshipPlugin().setup(registrar: registrar) + SwiftAirshipPlugin.shared.setup(registrar: registrar) } private func setup(registrar: FlutterPluginRegistrar) { @@ -667,19 +669,38 @@ extension FlutterMethodCall { class AirshipEventStreamHandler: NSObject, FlutterStreamHandler { private var eventSink: FlutterEventSink? + private var eventType: AirshipProxyEventType + + var onListenerAdded: () -> Void + + internal init( + eventSink: FlutterEventSink? = nil, + eventType: AirshipProxyEventType, + onListenerAdded: @escaping () -> Void + ) { + self.eventSink = eventSink + self.eventType = eventType + self.onListenerAdded = onListenerAdded + } - func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? { + func onListen( + withArguments arguments: Any?, + eventSink events: @escaping FlutterEventSink + ) -> FlutterError? { self.eventSink = events + onListenerAdded() return nil } func onCancel(withArguments arguments: Any?) -> FlutterError? { + self.eventSink = nil return nil } func notify(_ event: Any) -> Bool { if let sink = self.eventSink { + sink(event) return true } @@ -703,7 +724,13 @@ class AirshipEventStream: NSObject { name: self.name, binaryMessenger: registrar.messenger() ) - let handler = AirshipEventStreamHandler() + + let handler = AirshipEventStreamHandler(eventType: eventType) { + Task { [weak self] in + await self?.processPendingEvents() + } + } + eventChannel.setStreamHandler(handler) lock.sync { From 0d91442cc9c72d313bbba3b65255233329eaf7a3 Mon Sep 17 00:00:00 2001 From: crow Date: Fri, 25 Oct 2024 15:13:22 -0700 Subject: [PATCH 2/5] Update version --- .../src/main/kotlin/com/airship/flutter/AirshipPluginVersion.kt | 2 +- ios/Classes/AirshipPluginVersion.swift | 2 +- ios/airship_flutter.podspec | 2 +- pubspec.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/android/src/main/kotlin/com/airship/flutter/AirshipPluginVersion.kt b/android/src/main/kotlin/com/airship/flutter/AirshipPluginVersion.kt index bf9f7dc7..7c85fd26 100644 --- a/android/src/main/kotlin/com/airship/flutter/AirshipPluginVersion.kt +++ b/android/src/main/kotlin/com/airship/flutter/AirshipPluginVersion.kt @@ -2,6 +2,6 @@ package com.airship.flutter class AirshipPluginVersion { companion object { - const val AIRSHIP_PLUGIN_VERSION = "8.0.0" + const val AIRSHIP_PLUGIN_VERSION = "8.0.1" } } diff --git a/ios/Classes/AirshipPluginVersion.swift b/ios/Classes/AirshipPluginVersion.swift index 3136eb12..627aa475 100644 --- a/ios/Classes/AirshipPluginVersion.swift +++ b/ios/Classes/AirshipPluginVersion.swift @@ -1,5 +1,5 @@ import Foundation class AirshipPluginVersion { - static let pluginVersion = "8.0.0" + static let pluginVersion = "8.0.1" } diff --git a/ios/airship_flutter.podspec b/ios/airship_flutter.podspec index 6fcb6fd2..9dca2334 100644 --- a/ios/airship_flutter.podspec +++ b/ios/airship_flutter.podspec @@ -1,5 +1,5 @@ -AIRSHIP_FLUTTER_VERSION="8.0.0" +AIRSHIP_FLUTTER_VERSION="8.0.1" # # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html diff --git a/pubspec.yaml b/pubspec.yaml index a2cba709..82bc2a9b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: airship_flutter description: "Cross-platform plugin interface for the native Airship iOS and Android SDKs. Simplifies adding Airship to Flutter apps." -version: 8.0.0 +version: 8.0.1 homepage: https://www.airship.com/ repository: https://github.com/urbanairship/airship-flutter issue_tracker: https://github.com/urbanairship/airship-flutter/issues From 3b87aeb6099c2d2239cbc9bccf7c89ec1d90bd04 Mon Sep 17 00:00:00 2001 From: crow Date: Fri, 25 Oct 2024 15:22:54 -0700 Subject: [PATCH 3/5] Update CHANGELOG --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fd24364..efb0e6eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Flutter Plugin Changelog +## Version 8.0.1 - October 25, 2024 + +Patch release that fixes an issue with event streams that causes deep links to fail when the app is launched from a terminated state. Apps that use deep linking are encouraged to update. + +### Changes + +- Fixed event stream handling for initial events + ## Version 8.0.0 - October 24, 2024 Major version that makes it easier to include Airship in a hybrid app. The only breaking change is when extending the AirshipPluginExtender protocol on java there is a new extendConfig(Contex, AirshipConfigOptions.Builder) method to implement. Most application will not be affected. From a422a546547bf75c7f2c71e3327c8a72eb1804c6 Mon Sep 17 00:00:00 2001 From: crow Date: Fri, 25 Oct 2024 15:48:44 -0700 Subject: [PATCH 4/5] Update proxy --- android/build.gradle | 2 +- ios/airship_flutter.podspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 104d7ff1..00579332 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -5,7 +5,7 @@ buildscript { ext.kotlin_version = '1.9.0' ext.coroutine_version = '1.5.2' ext.datastore_preferences_version = '1.1.1' - ext.airship_framework_proxy_version = '11.0.0' + ext.airship_framework_proxy_version = '11.0.1' repositories { diff --git a/ios/airship_flutter.podspec b/ios/airship_flutter.podspec index 9dca2334..2ba70cb9 100644 --- a/ios/airship_flutter.podspec +++ b/ios/airship_flutter.podspec @@ -20,6 +20,6 @@ Airship flutter plugin. s.public_header_files = 'Classes/**/*.h' s.dependency 'Flutter' s.ios.deployment_target = "14.0" - s.dependency "AirshipFrameworkProxy", "11.0.0" + s.dependency "AirshipFrameworkProxy", "11.0.1" end From 33096c75dc54d6d2c7db96031b4f921bac9c78c6 Mon Sep 17 00:00:00 2001 From: crow Date: Fri, 25 Oct 2024 15:54:23 -0700 Subject: [PATCH 5/5] Update CHANGELOG --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index efb0e6eb..e619d4b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,14 +7,16 @@ Patch release that fixes an issue with event streams that causes deep links to f ### Changes - Fixed event stream handling for initial events +- Fixed tracking live activities started from a push notification ## Version 8.0.0 - October 24, 2024 -Major version that makes it easier to include Airship in a hybrid app. The only breaking change is when extending the AirshipPluginExtender protocol on java there is a new extendConfig(Contex, AirshipConfigOptions.Builder) method to implement. Most application will not be affected. +Major version that adds HMS support and makes it easier to include Airship in a hybrid app. The only breaking change is when extending the AirshipPluginExtender protocol on java there is a new extendConfig(Contex, AirshipConfigOptions.Builder) method to implement. Most application will not be affected. ### Changes - Added new methods to the plugin extender to make hybrid app integrations easier +- Added HMS support ## Version 7.9.0 - October 20, 2024