Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getting rootViewController #286

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AlexanderStrup
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants