简体   繁体   中英

flutter plugin development and iOS native code: avoid permission request on app launch?

Hi everyone and thanks in advance for your time and dedication on helping.

I'm developing a flutter plugin that requires access to the microphone. I have been able to do so but when I test the plugin (either with the example or using a new or existing app) I run into the following issue regarding microphone permission:

initial context:

the plugin itself does NOT request for permissions. This is a part of a bigger development and the idea is the app will request the permissions on a wizard like screen. What the plugin in does is to check if a giver permission is granted (in this case microphone)

Scenario 1: NSMicrophoneUsageDescription is absent on Info.plist

In this case running the app on a real device (always speaking on the context of debugging) will automatically crash. At this point I'm not calling any method that may try to use the microphone. In fact, if Im working with a new app just adding the dependency without importing anything results on the crash:

This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSMicrophoneUsageDescription key with a string value explaining to the user how the app uses this data.

Scenario 2: NSMicrophoneUsageDescription is present on Info.plist

This fixes the crash but also results on the app requesting the microphone permission as soon as it launches. This would be fine but it conflicts with the requirement of the wizard screen.

As I'm not an expert on Flutter Plugin development it may be this is the normal flow but I would find it odd. If this is the case, is there a way to avoid the app for requesting the permission so I can do it on demand?

Thanks again

edit 1:

I was asked to show code but just adding the library as a dependency triggers this.

Is it possible this is a debug thing?

edit 2:

The problem is a singleton pattern on the plugin root initialising the iOS native code. Thank you everyone

I have found what the problem was: The code uses a singleton as an entry point and the AudioEngine was being instanced. My bad on this one. Thanks everyone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM