【问题标题】:Unable to change NSCameraUsageDescription in Config.xml无法更改 Config.xml 中的 NSCameraUsageDescription
【发布时间】:2018-06-01 07:56:20
【问题描述】:

过去几天我一直在尝试解决这个问题,因为它阻止了我将更新部署到 iOS 应用商店。当我尝试其中一种解决方案时,我找到并构建了 .ipa 文件,然后我去检查 .plist 文件,但 NSCameraUsageDescription 属性从不显示我要显示的自定义消息。

我无法判断我是否做错了,因为我已经做了几乎所有我能找到的来解决这个问题。到目前为止,我已经尝试过this solution 和其他一些只是将格式更改为属性设置方式的方法。我还升级到了cordova版本,所以我也可以使用最新版本的相机插件来尝试解决这个问题。

这是我当前的 Config.xml 文件:(注释部分是我尝试过的其他方法。)

<widget xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0" id="com.devexpress.apptemplate" version="1.0" versionCode="1" xmlns:android="http://schemas.android.com/apk/res/android">
  <name>ApplicationTemplate</name>
  <preference name="prerendered-icon" value="true" />
  <preference name="android-windowSoftInputMode" value="adjustPan" />
  <preference name="SplashScreen" value="splash" />
  <preference name="SplashScreenDelay" value="3000" />
  <preference name="FadeSplashScreen" value="false" />
  <preference name="FadeSplashScreenDuration" value="2000" />
  <preference name="SplashShowOnlyFirstTime" value="false" />
  <preference name="DisallowOverscroll" value="true" />
  <preference name="StatusBarOverlaysWebView" value="false" />
  <preference name="StatusBarBackgroundColor" value="#000000" />
  <preference name="android-minSdkVersion" value="16" />
  <preference name="android-targetSdkVersion" value="26" />
  <preference name="android-build-tool" value="gradle" />
  <preference name="iosPersistentFileLocation" value="Compatibility" />
  <preference name="AndroidPersistentFileLocation" value="Compatibility" />
  <preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,assets,root" />

  <preference name='phonegap-version' value='cli-7.1.0' />
  <preference name='pgb-builder-version' value='1' />

  <feature name="http://api.phonegap.com/1.0/network" />

  <config-file platform="android" parent="/manifest" mode="add">
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CAMERA" />
  </config-file>

  <platform name="ios">
    <preference name="CAMERA_USAGE_DESCRIPTION" default=" " />
    <config-file target="*-Info.plist" parent="NSCameraUsageDescription">
      <string>Camera is used for uploading activation photos and profile pictures.</string>
    </config-file>
    <preference name="PHOTOLIBRARY_USAGE_DESCRIPTION" default=" " />
    <config-file target="*-Info.plist" parent="NSPhotoLibraryUsageDescription">
      <string>Photo Library is used for uploading activation photos and profile pictures.</string>
    </config-file>
   </platform>


   <!--<edit-config target="NSCameraUsageDescription" file="*-Info.plist" mode="overwrite">
    <string>Camera is used for uploading activation photos and profile pictures.</string>
  </edit-config>-->

    <!--<platform name="ios">
    <edit-config target="NSCameraUsageDescription" file="*-Info.plist" mode="merge">
      <string>Camera is used for uploading activation photos and profile pictures.</string>
    </edit-config>
    <edit-config target="NSPhotoLibraryUsageDescription" file="Info.plist" mode="merge">
      <string>Photo Library is used for uploading activation photos and profile pictures.</string>
    </edit-config>
  </platform>-->

  <preference name="ShowSplashScreenSpinner" value="false" />
  <author email="email@address.com" href="address.com">Description</author>

  <gap:plugin name="cordova-plugin-camera" version="4.0.3" source="npm" />
  <gap:plugin name="cordova-plugin-device" version="1.1.5" source="npm" />
  <gap:plugin name="cordova-plugin-file" version="4.2.0" source="npm" />
  <gap:plugin name="cordova-plugin-file-transfer" version="1.5.1" source="npm" />
  <gap:plugin name="cordova-plugin-geolocation" version="2.4.2" source="npm" />
  <gap:plugin name="cordova-plugin-network-information" source="npm" />
  <gap:plugin name="cordova-plugin-splashscreen" version="3.2.2" onload="true" source="npm" />
  <gap:plugin name="cordova-plugin-whitelist" source="npm" />
  <gap:plugin name="cordova-plugin-ios-longpress-fix" version="1.1.0" source="npm" />
  <gap:plugin name="cordova-plugin-statusbar" version="2.1.3" source="npm" onload="true" />
  <gap:plugin name="ionic-plugin-keyboard" source="npm" />
  <gap:plugin name="cordova-plugin-market" source="npm" />
  <gap:plugin name="cordova-plugin-appversion" source="npm" />
  <gap:plugin name="cordova.plugins.diagnostic" source="npm" />
  <plugin name="uk.co.workingedge.phonegap.plugin.launchnavigator" source="npm" />

  <access origin="*" />
  <access origin="tel:*" launch-external="yes" />
  <access origin="geo:*" launch-external="yes" />
</widget>

谁能看看我做错了什么?任何建议将不胜感激。

【问题讨论】:

    标签: ios cordova


    【解决方案1】:

    找到答案here

    您需要在config.xml 中使用edit-config。 像这样:

        <edit-config target="NSCameraUsageDescription" file="*-Info.plist" mode="merge">
          <string>need camera access to take pictures</string>
        </edit-config>
    

    【讨论】:

    • 感谢您的回复,但我已经尝试过了。我会再试一次以确定。
    • 为我工作 (ionic3)
    【解决方案2】:

    他们在 cli-7.0.1 中从使用 config-file 更改为 edit-config 以更好地与 plugin.xml 保持一致(好吧,至少这是我的理论)。

    阅读有关 plugin.xml 语法的文档(注意:它与配置文件不同!):https://cordova.apache.org/docs/en/latest/plugin_ref/spec.html

    【讨论】:

      【解决方案3】:

      也许已经晚了,但我认为值得回答,您需要从 Xcode 本身更新并将信息文件中的密钥添加为

      点赞Sample code ScreenShot

      现在检查您项目的 info.plist,代码应该像这样添加到那里

      <key>NSCameraUsageDescription</key>
      <string>APPNAME requires access to your phone's camera for this PURPOSE.</string>
      

      现在,从 Xcode 清理您的项目并再次构建,您的应用现在应该可以正常工作了。

      我有 Xcode 10.3 版,它在这个解决方案中运行良好。

      希望这对任何人都有帮助!

      【讨论】:

        【解决方案4】:

        根据我的经验,config.xml 文件的更改只有在添加平台(或 plugin.xml 包含新权限的插件)时才会传播。

        换句话说,如果您更改了与 Android 或 iOS 相关的权限或使用说明,并且更改未出现在您 cordova buildcordova emulatecordova run 之后,那么您可能需要删除并重新添加合适的平台:

        • cordova platform rm android; cordova platform add android
        • cordova platform rm ios; cordova platform add ios

        【讨论】:

          猜你喜欢
          • 2016-11-12
          • 1970-01-01
          • 1970-01-01
          • 2020-12-22
          • 1970-01-01
          • 1970-01-01
          • 2017-03-19
          • 2018-04-12
          • 1970-01-01
          相关资源
          最近更新 更多