Skip to content

Commit

Permalink
Merge pull request #225 from urbanairship/fix_dl
Browse files Browse the repository at this point in the history
Fix event streams on android and ios
  • Loading branch information
crow authored Oct 25, 2024
2 parents 23ef113 + 33096c7 commit 10730d7
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 20 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
# 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
- 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

Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
33 changes: 24 additions & 9 deletions android/src/main/kotlin/com/airship/flutter/AirshipPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<EventChannel.EventSink?> get() = _eventSink

private var _eventSink: MutableStateFlow<EventChannel.EventSink?> = 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(
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion ios/Classes/AirshipPluginVersion.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation

class AirshipPluginVersion {
static let pluginVersion = "8.0.0"
static let pluginVersion = "8.0.1"
}
35 changes: 31 additions & 4 deletions ios/Classes/SwiftAirshipPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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] = [
Expand All @@ -29,8 +29,10 @@ public class SwiftAirshipPlugin: NSObject, FlutterPlugin {

private var subscriptions = Set<AnyCancellable>()

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) {
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions ios/airship_flutter.podspec
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 10730d7

Please sign in to comment.