istornz / flutter_live_activities

A Flutter plugin to use iOS 16.1+ Live Activities ⛹️ & iPhone Dynamic Island 🏝️ features
https://dimitridessus.fr/
MIT License
183 stars 55 forks source link

Sending a message before the FlutterEngine has been run. #59

Open ErayAltas opened 1 year ago

ErayAltas commented 1 year ago

Issue: Fatal Exception: NSInternalInconsistencyException Sending a message before the FlutterEngine has been run. Fatal Exception: NSInternalInconsistencyException 0 CoreFoundation 0x9cb4 __exceptionPreprocess 1 libobjc.A.dylib 0x183d0 objc_exception_throw 2 Foundation 0x4e154c _userInfoForFileAndLine 3 Flutter 0x1ba6c (Missing UUID 4c4c44c655553144a12489c324693308) 4 Flutter 0x5d75e0 (Missing UUID 4c4c44c655553144a12489c324693308) 5 live_activities 0x4470 thunk for @escaping @callee_unowned @convention(block) (@unowned Swift.AnyObject?) -> () () 6 liveactivities 0xa458 (3) suspend resume partial function for specialized closure #1 in SwiftLiveActivitiesPlugin.monitorLiveActivity(:) + 359 (SwiftLiveActivitiesPlugin.swift:359) 7 liveactivities 0x1381d (1) await resume partial function for partial apply for specialized closure #1 in SwiftLiveActivitiesPlugin.monitorLiveActivity(:) 8 live_activities 0xb8f1 (1) await resume partial function for specialized thunk for @escaping @callee_guaranteed @Sendable @async () -> (@out A) () 9 live_activities 0x13865 (1) await resume partial function for partial apply for specialized thunk for @escaping @callee_guaranteed @Sendable @async () -> (@out A) 10 libswift_Concurrency.dylib 0x48dd9 completeTaskWithClosure(swift::AsyncContext, swift::SwiftError)

Issue on swift file, it points this function:

@available(iOS 16.1, *) private func monitorLiveActivity(_ activity: Activity) { Task { for await state in activity.activityStateUpdates { var response: Dictionary<String, Any> = Dictionary() response["activityId"] = activity.id switch state { case .active: monitorTokenChanges(activity) case .dismissed, .ended: response["status"] = "ended" activityEventSink?.self(response) case .stale: response["status"] = "stale" activityEventSink?.self(response) @unknown default: response["status"] = "unknown" activityEventSink?.self(response) } } } }

The application crashes because of this line.

I think the reason for this is that when the Flutter application is closed, the live activity is also tried to be closed, but this error may occur because the Flutter app disappears first and the live activity update is tried to be transmitted to the Flutter app later.

The error line //// case .dismissed, .ended: response["status"] = "ended" activityEventSink?.self(response) /////

ggirotto commented 10 months ago

I strongly believe this is related with Flutter engine. See https://github.com/flutter/flutter/issues/117523 for a more in-depth discussions. There's nothing we can do but wait...