Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
405 views
in Technique[技术] by (71.8m points)

ios - flutter popup is not coming to ask permission to access camera

i try to request camera permission on real iphone to scan qr code using qr_code_scanner but the popup doesn't open i add NSCameraUsageDescription in info.plist and added in my podfile this

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
  config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
    '$(inherited)',
     'PERMISSION_CAMERA=0',
     'PERMISSION_PHOTOS=0',
     'PERMISSION_MEDIA_LIBRARY=0',
  ]
    end
  end 
end

and this my code for ask i try this

getCamera() async {
   var status = await Permission.camera.status;
  if (!status.isGranted) {
  final result = await Permission.camera.request();
  if (result.isGranted) {
    setState(() {
    getPerm = true;
    });
  }
  } else {
  setState(() {
    getPerm = true;
  });
  }
}

and this

void initState() {
super.initState();
  WidgetsBinding.instance.addPostFrameCallback(onLayoutDone);
 }
      void onLayoutDone(Duration timeStamp) async {
    _permissionStatus = await Permission.camera.status;
    if (_permissionStatus.isGranted) {
      setState(() {
        getPerm = true;
      });
    }
  }

  void _askCameraPermission() async {
    await Permission.camera.request();
    if (await Permission.camera.request().isGranted) {
      _permissionStatus = await Permission.camera.status;
      setState(() {
        getPerm = true;
      });
    }
  } 

and call _askCameraPermission function on pressed in button nothing of this ways is working with me and all Permission other than camera working

question from:https://stackoverflow.com/questions/65838026/flutter-popup-is-not-coming-to-ask-permission-to-access-camera

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Are you running your app on simulator or real device? Here is the similar issue for you plugin.

Also you can try:

  1. check camera availability for your app in app settings in iOS;
  2. debug your app for check permission status.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...