简体   繁体   English

flutter 插件开发和 iOS 本机代码:避免应用启动时的权限请求?

[英]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:我已经能够这样做,但是当我测试插件(使用示例或使用新的或现有的应用程序)时,我遇到了有关麦克风权限的以下问题:

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场景 1:Info.plist 上没有NSMicrophoneUsageDescription

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 键和一个字符串值,向用户解释应用程序如何使用这些数据。

Scenario 2: NSMicrophoneUsageDescription is present on Info.plist场景 2: NSMicrophoneUsageDescription存在于 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.由于我不是 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再次感谢

edit 1:编辑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:编辑2:

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.

相关问题 如何避免应用在启动时请求许可? - How to avoid app asking permission on launch? 拒绝后的权限请求 flutter 应用程序 - Permission request flutter app after denial 来自本机应用程序的Web推送权限请求 - Web push permission request from native app 在本机代码中使用opencv进行Android应用开发 - Using opencv in native code for Android app development 本机代码在Android / iPhone应用程序开发中的影响 - The impact of native code in Android/iPhone app development 使用 apktool 使应用程序请求 android 启动权限 - Making app request android permission on launch using apktool iOS 相机权限,本机 iOS 权限警报未在第一次请求时触发 - iOS camera permissions, native iOS permission alert not firing on first request 在 Flutter 代码中等待异步本机请求的完成 - Wait in Flutter Code for Completion of Async Native Request React Native:Android而非iOS的开发服务器返回有关App.js导入路径的错误代码500 - React Native: The development server return response error code 500 about App.js import path for Android but not iOS 在React-Native中同时开发iOS和Android应用程序 - Simultaneously development of iOS and Android app in React-Native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM