[英]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.我正在开发一个需要访问麦克风的 flutter 插件。 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:我已经能够这样做,但是当我测试插件(使用示例或使用新的或现有的应用程序)时,我遇到了有关麦克风权限的以下问题:
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)插件的作用是检查是否授予了授予者权限(在本例中为麦克风)
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.应用程序的 Info.plist 必须包含一个 NSMicrophoneUsageDescription 键和一个字符串值,向用户解释应用程序如何使用这些数据。
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.由于我不是 Flutter 插件开发方面的专家,因此这可能是正常流程,但我会觉得这很奇怪。 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再次感谢
I was asked to show code but just adding the library as a dependency triggers this.我被要求显示代码,但只是将库添加为依赖项会触发此操作。
Is it possible this is a debug thing?这可能是调试的事情吗?
The problem is a singleton pattern on the plugin root initialising the iOS native code.问题是插件根目录上的 singleton 模式初始化 iOS 本机代码。 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.我发现了问题所在:代码使用 singleton 作为入口点,并且正在实例化 AudioEngine。 My bad on this one.我对这个不好。 Thanks everyone.感谢大家。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.