在 config.xml 中设置使用说明后,Ionic IOS 相机权限仍然被拒绝

Posted

技术标签:

【中文标题】在 config.xml 中设置使用说明后,Ionic IOS 相机权限仍然被拒绝【英文标题】:Ionic IOS Camera permission still denied after set usage description in config.xml 【发布时间】:2021-07-01 04:16:15 【问题描述】:

我想问一下,当我已经在配置 xml 中设置了 NSCameraUsageDescription 时,为什么我仍然没有 ios 设备的摄像头权限。下面的附件照片是我运行相机功能时遇到的错误。在此之前,config.xml 对我来说是隐藏的,我使用 ionic integrations enable cordova --add 来启用和配置它。

   <platform name="ios">
       <allow-intent href="itms:*" />
       <allow-intent href="itms-apps:*" />
       <config-file parent="NSCameraUsageDescription" platform="ios" target="*-Info.plist">
           <string>You can take photos</string>
       </config-file>
       <icon  src="resources/ios/icon/icon.png"  />
       <icon  src="resources/ios/icon/icon@2x.png"  />
       <icon  src="resources/ios/icon/icon-small.png"  />
       <icon  src="resources/ios/icon/icon-small@2x.png"  />
       <icon  src="resources/ios/icon/icon-small@3x.png"  />
       <icon  src="resources/ios/icon/icon-20.png"  />
       <icon  src="resources/ios/icon/icon-20@2x.png"  />
       <icon  src="resources/ios/icon/icon-20@3x.png"  />
       <icon  src="resources/ios/icon/icon-24@2x.png"  />
       <icon  src="resources/ios/icon/icon-27.5@2x.png"  />
       <icon  src="resources/ios/icon/icon-29.png"  />
       <icon  src="resources/ios/icon/icon-29@2x.png"  />
       <icon  src="resources/ios/icon/icon-29@3x.png"  />
       <icon  src="resources/ios/icon/icon-40.png"  />
       <icon  src="resources/ios/icon/icon-40@2x.png"  />
       <icon  src="resources/ios/icon/icon-40@3x.png"  />
       <icon  src="resources/ios/icon/icon-44@2x.png"  />
       <icon  src="resources/ios/icon/icon-50.png"  />
       <icon  src="resources/ios/icon/icon-50@2x.png"  />
       <icon  src="resources/ios/icon/icon-60.png"  />
       <icon  src="resources/ios/icon/icon-60@2x.png"  />
       <icon  src="resources/ios/icon/icon-60@3x.png"  />
       <icon  src="resources/ios/icon/icon-72.png"  />
       <icon  src="resources/ios/icon/icon-72@2x.png"  />
       <icon  src="resources/ios/icon/icon-76.png"  />
       <icon  src="resources/ios/icon/icon-76@2x.png"  />
       <icon  src="resources/ios/icon/icon-83.5@2x.png"  />
       <icon  src="resources/ios/icon/icon-86@2x.png"  />
       <icon  src="resources/ios/icon/icon-98@2x.png"  />
       <icon  src="resources/ios/icon/icon-1024.png"  />
       <splash  src="resources/ios/splash/Default~iphone.png"  />
       <splash  src="resources/ios/splash/Default@2x~iphone.png"  />
       <splash  src="resources/ios/splash/Default-Portrait~ipad.png"  />
       <splash  src="resources/ios/splash/Default-Landscape~ipad.png"  />
       <splash  src="resources/ios/splash/Default-Landscape-2436h.png"  />
       <splash  src="resources/ios/splash/Default-Landscape-736h.png"  />
       <splash  src="resources/ios/splash/Default-Portrait@2x~ipad.png"  />
       <splash  src="resources/ios/splash/Default-Landscape@2x~ipad.png"  />
       <splash  src="resources/ios/splash/Default-Portrait@~ipadpro.png"  />
       <splash  src="resources/ios/splash/Default-Landscape@~ipadpro.png"  />
       <splash  src="resources/ios/splash/Default-568h@2x~iphone.png"  />
       <splash  src="resources/ios/splash/Default-667h.png"  />
       <splash  src="resources/ios/splash/Default-736h.png"  />
       <splash  src="resources/ios/splash/Default-2436h.png"  />
       <splash  src="resources/ios/splash/Default@2x~universal~anyany.png"  />
   </platform>
   <plugin name="cordova-plugin-whitelist" spec="1.3.3" />
   <plugin name="cordova-plugin-statusbar" spec="2.4.2" />
   <plugin name="cordova-plugin-device" spec="2.0.2" />
   <plugin name="cordova-plugin-splashscreen" spec="5.0.2" />
   <plugin name="cordova-plugin-ionic-webview" spec="^4.0.0" />
   <plugin name="cordova-plugin-ionic-keyboard" spec="^2.0.5" />
</widget>

xCode Console log

Config xml

【问题讨论】:

在xcode的info.plist文件中添加摄像头权限。 【参考方案1】:

从 Cordova CLI 6.5.0 开始,您可以使用 config.xml 中的 edit-config 标记直接在 info.plist 中写入,如下所示:

<platform name="ios">

 <edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge" overwrite="true">
      <string>YOUR-PERMISSION-REQUEST</string>
 </edit-config>
 <edit-config target="NSPhotoLibraryUsageDescription" file="*-Info.plist" mode="merge" overwrite="true" >
      <string>YOUR-PERMISSION-REQUEST</string>
 </edit-config>
 <edit-config target="NSCameraUsageDescription" file="*-Info.plist" mode="merge" overwrite="true">
      <string>YOUR-PERMISSION-REQUEST</string>
 </edit-config>
</platform>

并确保您使用的是最新版本的插件,否则值可能会被插件变量覆盖。

【讨论】:

感谢您的建议,我会将其标记为问题的解决方案

以上是关于在 config.xml 中设置使用说明后,Ionic IOS 相机权限仍然被拒绝的主要内容,如果未能解决你的问题,请参考以下文章

在本地通知中设置repeatInterval

如何在协议扩展中设置委托

PhoneGap:修改 config.xml 以将属性添加到 Info.plist ion iOS

在批处理文件中设置日期格式

如何在 Angular/Ionic 框架中设置离子输入的样式?

如何在 application.properties 中设置文件夹位置?