From 513162e92015a4433f1e479dd4af17998834a95a Mon Sep 17 00:00:00 2001 From: Tuong Nguyen Manh Date: Wed, 3 Jan 2024 16:58:08 +0100 Subject: [PATCH 1/3] Fixed found devices sometimes never appearing on the Dart side under iOS --- ios/Classes/MPCManager.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ios/Classes/MPCManager.swift b/ios/Classes/MPCManager.swift index 9f0014d..b59c70b 100644 --- a/ios/Classes/MPCManager.swift +++ b/ios/Classes/MPCManager.swift @@ -167,6 +167,9 @@ extension MPCManager: MCNearbyServiceBrowserDelegate { func browser(_ browser: MCNearbyServiceBrowser, foundPeer peerID: MCPeerID, withDiscoveryInfo info: [String : String]?) { // found peer, create a device with this peerID addNewDevice(for: peerID) + + // Inform about changed device state via NotificationCenter to guarantee main thread execution. + NotificationCenter.default.post(name: MPCManager.Notifications.deviceDidChangeState, object: nil) } func browser(_ browser: MCNearbyServiceBrowser, lostPeer peerID: MCPeerID) { From 05848c604c90ce51756364ff3bf9037fd39d4a6b Mon Sep 17 00:00:00 2001 From: Stefan Eilers Date: Fri, 12 Jan 2024 13:46:06 +0100 Subject: [PATCH 2/3] Fix reason of crash. The connectionclient was not initialized (due to unknown reason) while he tried to destroy the service. --- .../nankai/flutter_nearby_connections/NearbyService.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/android/src/main/kotlin/com/nankai/flutter_nearby_connections/NearbyService.kt b/android/src/main/kotlin/com/nankai/flutter_nearby_connections/NearbyService.kt index ab16b94..abf3d53 100644 --- a/android/src/main/kotlin/com/nankai/flutter_nearby_connections/NearbyService.kt +++ b/android/src/main/kotlin/com/nankai/flutter_nearby_connections/NearbyService.kt @@ -92,10 +92,12 @@ class NearbyService : Service() { } override fun onDestroy() { + if (this::connectionsClient.isInitialized) { + stopAdvertising() + stopDiscovery() + connectionsClient.stopAllEndpoints() + } super.onDestroy() - stopAdvertising() - stopDiscovery() - connectionsClient.stopAllEndpoints() } private fun getNotification(): Notification? { @@ -118,4 +120,4 @@ class NearbyService : Service() { internal class LocalBinder(private val nearbyService: NearbyService) : Binder() { val service: NearbyService get() = nearbyService -} \ No newline at end of file +} From 7222c78c8891cb90a3f0c6fc212d85c812709495 Mon Sep 17 00:00:00 2001 From: Stefan Eilers Date: Fri, 19 Jan 2024 13:54:38 +0100 Subject: [PATCH 3/3] #235: An other crash due to not initialized lateinit .. --- .../FlutterNearbyConnectionsPlugin.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/android/src/main/kotlin/com/nankai/flutter_nearby_connections/FlutterNearbyConnectionsPlugin.kt b/android/src/main/kotlin/com/nankai/flutter_nearby_connections/FlutterNearbyConnectionsPlugin.kt index 54f268c..f23465f 100644 --- a/android/src/main/kotlin/com/nankai/flutter_nearby_connections/FlutterNearbyConnectionsPlugin.kt +++ b/android/src/main/kotlin/com/nankai/flutter_nearby_connections/FlutterNearbyConnectionsPlugin.kt @@ -136,9 +136,11 @@ class FlutterNearbyConnectionsPlugin : FlutterPlugin, MethodCallHandler, Activit override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) { channel.setMethodCallHandler(null) - serviceBindManager.mService?.stopAdvertising() - serviceBindManager.mService?.stopDiscovery() - serviceBindManager.unbindService() + if (this::serviceBindManager.isInitialized) { + serviceBindManager.mService?.stopAdvertising() + serviceBindManager.mService?.stopDiscovery() + serviceBindManager.unbindService() + } locationHelper = null exitProcess(0) }