flutter_contacts
flutter_contacts copied to clipboard
Fix getting rootViewController
I created flutter module to use it as library in native app. I used your plugin to get contacts. But I had runtime error in native app when tried to register plugins
GeneratedPluginRegistrant.register(with: flutterEngine);
SwiftContactsServicePlugin.swift:16: Fatal error: Unexpectedly found nil while unwrapping an Optional value
Line 16 in SwiftContactsServicePlugin.swift:
let rootViewController = UIApplication.shared.delegate!.window!!.rootViewController!;
I did it according Flutter Docs to interaction with my module. I tried add window variable to my AppDelegate but it didn't help. iOS 13+ has new methods and classes for getting window. With my changes I got the rootViewController but I think the runtime error is bad practice anyway so just add an error message to log when rootViewController still nil.