flutter ios permission_handle权限动态申请
文章目录
- 配置
- permission_handle
- Android项目
- IOS项目
- 代码
网上都是针对安卓的教程,以下是作者使用Flutter打包在iphone上运行动态申请权限的实战记录。
项目在:https://github.com/xmcy0011/CoffeeChat
开源IM解决方案,包含服务端(go)和客户端(Flutter)。单聊和机器人(小微、图灵、思知)聊天功能已完成,目前正在研发群聊功能。
配置
permission_handle
在pubspec.yaml中增加
dependencies:flutter:sdk: flutter# The following adds the Cupertino Icons font to your application.# Use with the CupertinoIcons class for iOS style icons....permission_handler: ^3.0.0 # 权限
Android项目
在AndroidManifest.xml中增加:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.coffeechat.cc_flutter_app"><!-- io.flutter.app.FlutterApplication is an android.app.Application thatcalls FlutterMain.startInitialization(this); in its onCreate method.In most cases you can leave this as-is, but you if you want to provideadditional functionality it is fine to subclass or reimplementFlutterApplication and put your custom class here. --><applicationandroid:name="io.flutter.app.FlutterApplication"android:label="CoffeeChat"android:icon="@mipmap/ic_launcher"><activityandroid:name=".MainActivity"android:launchMode="singleTop"android:theme="@style/LaunchTheme"android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"android:hardwareAccelerated="true"android:windowSoftInputMode="adjustResize"><!-- This keeps the window background of the activity showinguntil Flutter renders its first frame. It can be removed ifthere is no splash screen (such as the default splash screendefined in @style/LaunchTheme). --><meta-dataandroid:name="io.flutter.app.android.SplashScreenUntilFirstFrame"android:value="true" /><intent-filter><action android:name="android.permission.INTERNET"/># 你的权限# 我这边申请了,摄像头和麦克风# 列表在https://pub.flutter-io.cn/packages/permission_handler# “List of available permissions” 一节<action android:name="android.permission.CAMERA"/><action android:name="android.permission.Microphone"/><action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER"/></intent-filter></activity></application>
</manifest>
IOS项目
1.Podfile中增加
post_install do |installer|installer.pods_project.targets.each do |target|target.build_configurations.each do |config|config.build_settings['ENABLE_BITCODE'] = 'NO'# 以下是新增的,permission_handle中动态申请摄像头、麦克风权限# 权限列表参考:https://pub.flutter-io.cn/packages/permission_handler# "Add the following to your Podfile file" 一节# You can remove unused permissions here# for more infomation: https://github.com/BaseflowIT/flutter-permission-handler/blob/develop/ios/Classes/PermissionHandlerEnums.h# e.g. when you don't need camera permission, just add 'PERMISSION_CAMERA=0'config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)',## dart: PermissionGroup.camera'PERMISSION_CAMERA=0',## dart: PermissionGroup.microphone'PERMISSION_MICROPHONE=0',]endend
end
2.Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict><key>CFBundleDevelopmentRegion</key><string>$(DEVELOPMENT_LANGUAGE)</string><key>CFBundleExecutable</key><string>$(EXECUTABLE_NAME)</string><key>CFBundleIdentifier</key><string>$(PRODUCT_BUNDLE_IDENTIFIER)</string><key>CFBundleInfoDictionaryVersion</key><string>6.0</string><key>CFBundleName</key><string>CoffeeChat</string><key>CFBundlePackageType</key><string>APPL</string><key>CFBundleShortVersionString</key><string>$(FLUTTER_BUILD_NAME)</string><key>CFBundleSignature</key><string>????</string><key>CFBundleVersion</key><string>$(FLUTTER_BUILD_NUMBER)</string><key>LSRequiresIPhoneOS</key><true/># 这里是新增的,具体参考https://pub.flutter-io.cn/packages/permission_handler# “Delete the corresponding permission description in Info.plist” 一节# 这里申请摄像头和麦克风,如果Info.plist不添加这4行,将直接崩溃<key>NSCameraUsageDescription</key><string>The app tries to use your camera</string><key>NSMicrophoneUsageDescription</key><string>The app tries to use your microphone</string><key>UILaunchStoryboardName</key><string>LaunchScreen</string><key>UIMainStoryboardFile</key><string>Main</string><key>UISupportedInterfaceOrientations</key><array><string>UIInterfaceOrientationPortrait</string><string>UIInterfaceOrientationLandscapeLeft</string><string>UIInterfaceOrientationLandscapeRight</string></array><key>UISupportedInterfaceOrientations~ipad</key><array><string>UIInterfaceOrientationPortrait</string><string>UIInterfaceOrientationPortraitUpsideDown</string><string>UIInterfaceOrientationLandscapeLeft</string><string>UIInterfaceOrientationLandscapeRight</string></array><key>UIViewControllerBasedStatusBarAppearance</key><false/>
</dict>
</plist>
代码
关键代码如下
_handleCameraAndMic() async {// 请求权限Map<PermissionGroup, PermissionStatus> permissions = await PermissionHandler().requestPermissions([PermissionGroup.camera, PermissionGroup.microphone],);//校验权限if (permissions[PermissionGroup.camera] != PermissionStatus.granted) {print("无照相权限");return false;}if (permissions[PermissionGroup.microphone] != PermissionStatus.granted) {print("无麦克风权限");return false;}return true;}void _onVoiceCall() async {// await for camera and mic permissions before pushing video pageif (await _handleCameraAndMic()) {navigatePushPage(this.context,new PageAVChatCallerStatefulWidget(Int64(this.sessionInfo.sessionId), this.sessionInfo.sessionName));}}
flutter ios permission_handle权限动态申请相关推荐
- android manifest 权限组,Android的单个或多个权限动态申请
前言 在Android 6.0(API 级别 23)以下申请权限是非常简单的,直接在AndroidManifest.xml这个配置文件中加入申请权限的列表就可以了,比如我要申请四个权限,如下: 但是在 ...
- android 权限动态申请
名字其实有点让人感觉高大上"权限动态申请",其实也没有什么, 以前做Android程序的时候,比如需要打开摄像头 那么需要在 然后就可以了, 但是Android6.0之后呢,有些权 ...
- android位置权限动态申请,DELPHI安卓定位权限申请
DELPHI安卓定位权限申请 安卓8及以后版本的权限分为静态和动态申请2部分,而之前的安卓版本只需要静态申请权限. 1)静态申请定位权限: 2)动态申请定位权限: uses System.Permis ...
- Qt for Android 动态申请权限
前言 Qt 随着版本的不断更新,提供了越来越多的接口用于移动端的开发,这里要说的是关于 Android 上权限动态申请的问题,直接在 C++端调用 Qt 的接口即可以实现. 正文 Qt 申请Andro ...
- Android 系统(81)---Android permission 动态申请、授权
Android permission 动态申请.授权 Android permission 学习 本篇文章介绍android permission系统,并介绍android 6.0 .7.0.8.0 ...
- flutter permission动态权限申请以及IOS端权限问题审核被拒处理
前言 Google在 Android 6.0 开始引入了权限申请机制,将所有权限分成了正常权限和危险权限.应用的相关功能每次在使用危险权限时需要动态的申请并得到用户的授权才能使用,否则将会导致应用程序 ...
- 【flutter】使用permission_handler配置android和 iOS的权限
文章目录 前言 准备工作 一.使用步骤 1.使用的插件 2.配置权限 二.代码示例 三.结果截图 前言 flutter在pub.flutter-io.cn插件库中有很多的关于权限配置的插件,但是就我个 ...
- android 动态申请权限_你真的了解Android权限机制吗?
码个蛋(codeegg)第 610 次推文 作者:FeelsChaotic 原文:https://www.jianshu.com/p/a17c8bed79d9 前言 Android将安全设计贯穿系统架 ...
- EasyPermission:一句代码解决动态权限的申请和回执(带权限提示信息)
效果展示 以上是演示请求一个相机权限的过程: 首次申请(顶部提醒)-拒绝-再次申请(顶部提醒)-再次拒绝(并勾选禁止再次询问)-再次申请(中部弹窗引导)-在设置页不授权-返回-再次申请(中部弹窗引导) ...
最新文章
- C++知识点58——类模板(3、类模板的成员模板)
- 关于git fetch 和git pull 的区别
- 【城市沙龙】LiveVideoStack Meet | 长沙:多媒体与广电
- sublime:查看二进制文件
- python自动回复机器人手机版_GitHub - HZQHZA/wxpy: Python 写 微信聊天 根据 自动回复 接入机器人 等等.......
- DBMS_STATS常用方法(收集oracle信息)
- arm-linux启动,linux启动流程arm
- 超级素数幂--全国模拟(一)
- IDEA 使用和问题总结
- fcntl函数与整数常量O_ACCMODE
- cas4.x 单点登录开发入门
- 极光设置一级二级标题
- 行业承压虎牙营收持续稳健,电竞浪潮中把握长期价值
- 解压缩软件:WinRAR V5.71
- 从打造“兴趣电商”到“完全闭环”,抖音电商之路
- [LeetCode][沙雕氵]如何用LeetCode130写一个故事?
- lamp兄弟连PHP视频教程 笔记心得
- 【C++】vector的基本使用
- centos 开发套件_替代的Laravel套件开发工作流程
- MySql定期备份数据到历史表的解决方案
热门文章
- 捋一捋Python的文件属性和增删查改等(下)
- Unity Shader 之 简单实现折叠平面(翻书)的效果
- 【愚公系列】2021年12月 Python教学课程 19-面向对象编程-面向对象定义
- 极限与连续和可导的关系
- ETL工具(数据同步)
- vulkan_笔记1
- 前端做CRM管理系统是做什么_悟空CRM:CRM系统能够帮助企业做什么?
- css旋转动画定义中心,CSS实现弹簧效果的旋转加载动画
- CSS常用选择器(通配符选择器,标签选择器,类选择器,id选择器.....),你知道多少?
- orchard mysql_Orchard Core学习一