New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS 10 requires Camera permission reason #270

Closed
EddyVerbruggen opened this Issue Jun 27, 2016 · 54 comments

Comments

Projects
None yet
@EddyVerbruggen
Copy link
Member

EddyVerbruggen commented Jun 27, 2016

Your app will crash if you don't provide a 'usage description' for the Camera permission prompt.

I'll add an empty reason for now.

@pke

This comment has been minimized.

Copy link

pke commented Jun 28, 2016

Couldn't that use a config.xml preference instead of an empty string?

@EddyVerbruggen

This comment has been minimized.

Copy link
Member Author

EddyVerbruggen commented Jun 28, 2016

You can override it - this is just so your app doesn't crash if you don't.

Note that I've also done this and documented a way to override it for the NativeScript barcodescanner plugin - we could do the same here.

@jcesarmobile

This comment has been minimized.

Copy link
Collaborator

jcesarmobile commented Jun 28, 2016

Right now it's not possible to add that from config.xml, you'll have to use another plugin that writes to the info.plist

@pke

This comment has been minimized.

Copy link

pke commented Jun 28, 2016

@jcesarmobile I was under the impression plugins can read config preferences like this in plugin.xml:

<preference name="CAMERA_PERMISSION_REASON" />

<platform name="ios">
  <config-file target="*-Info.plist" parent="NSCameraUsageDescription">
    <string>$CAMERA_PERMISSION_REASON</string>
  </config-file>
</platform>
@jcesarmobile

This comment has been minimized.

Copy link
Collaborator

jcesarmobile commented Aug 2, 2016

No, that is for reading variables passed on plugin install, but I think it's a good option to do it with a variable.
I've sent a PR to the contacts plugin following this approach because it has the same problem, you can take a look.
apache/cordova-plugin-contacts#131

macdonst added a commit that referenced this issue Sep 5, 2016

@jcesarmobile

This comment has been minimized.

Copy link
Collaborator

jcesarmobile commented Sep 6, 2016

#271 was merged, but I'm not closing this yet as I think we should add a way to provide the UsageDescription instead of using an empty string

@pke

This comment has been minimized.

Copy link

pke commented Sep 6, 2016

Can't this be solved by using a plugin variable or better a preference?

@jcesarmobile

This comment has been minimized.

Copy link
Collaborator

jcesarmobile commented Sep 6, 2016

Yes, it can be solved using a plugin variable, see the PR I linked contacts plugin.
But sadly no, a preference can't be used, I tried and didn't work

@macdonst macdonst self-assigned this Sep 6, 2016

@jcesarmobile

This comment has been minimized.

Copy link
Collaborator

jcesarmobile commented Sep 7, 2016

BTW, you can add the variable on the config.xml

This is what is added when you install the camera plugin with the variable and the --save param. I've tried to add that on a new empty project, just adding this lines on the config.xml and when I add iOS platform the plugin is added and the variable is passed.

<plugin name="cordova-plugin-camera" spec="https://github.com/apache/cordova-plugin-camera">
        <variable name="CAMERA_USAGE_DESCRIPTION" value="your usage message" />
</plugin>

macdonst added a commit that referenced this issue Sep 7, 2016

@macdonst

This comment has been minimized.

Copy link
Member

macdonst commented Sep 7, 2016

@jcesarmobile can you take a look at my latest commit. I believe it resolves this issue but I want a second opinion. If it LGT you close this issue and maybe we can do a new plugin release.

@jcesarmobile

This comment has been minimized.

Copy link
Collaborator

jcesarmobile commented Sep 7, 2016

Yes, it looks good, closing.

@michaljakubowski

This comment has been minimized.

Copy link

michaljakubowski commented Sep 17, 2016

Is there a possibility to set different messages for each language?

@geoHeil

This comment has been minimized.

Copy link

geoHeil commented Sep 30, 2016

I have set it up like:

<plugin name="cordova-plugin-camera" spec="~2.2.0">
        <variable name="CAMERA_USAGE_DESCRIPTION" value="my message" />
        <variable name="NSPHOTOLIBRARYUSAGEDESCRIPTIONENTRY" value="my message" />
    </plugin>

In the config.xml

However, these values are not transferred to xcode / the info.plist file when the ios platform is added.

@jcesarmobile

This comment has been minimized.

Copy link
Collaborator

jcesarmobile commented Sep 30, 2016

that change was included in 2.3.0, so try changing to spec="~2.3.0"

@geoHeil

This comment has been minimized.

Copy link

geoHeil commented Sep 30, 2016

Thanks. However, it still does not work.

jcesarmobile notifications@github.com schrieb am Fr., 30. Sep. 2016 um
11:21 Uhr:

that change was included in 2.3.0, so try changing to spec="~2.3.0"


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#270 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABnc9II6gchdrF_dL6lNS13VlKHesGH2ks5qvNR9gaJpZM4I_Mgj
.

@jcesarmobile

This comment has been minimized.

Copy link
Collaborator

jcesarmobile commented Sep 30, 2016

Try removing platforms and plugins folders and adding ios platform again

Also, for photo library is PHOTOLIBRARY_USAGE_DESCRIPTION, not NSPHOTOLIBRARYUSAGEDESCRIPTIONENTRY

@pke

This comment has been minimized.

Copy link

pke commented Sep 30, 2016

Also, for photo library is PHOTOLIBRARY_USAGE_DESCRIPTION, not NSPHOTOLIBRARYUSAGEDESCRIPTIONENTRY

That might be the reason. I already wondered what strange, non snake'ish, name NSPHOTOLIBRARYUSAGEDESCRIPTIONENTRY would be.

@pke

This comment has been minimized.

Copy link

pke commented Sep 30, 2016

How can this be localized? Can't we add a language specifier to the <string> tag?

@jcesarmobile

This comment has been minimized.

Copy link
Collaborator

jcesarmobile commented Sep 30, 2016

To localize you can read this answer, but it's for native projects, not Cordova ones http://stackoverflow.com/questions/25736700/how-to-localise-a-string-inside-the-ios-info-plist-file

@benface

This comment has been minimized.

Copy link

benface commented Oct 10, 2016

@geoHeil Were you able to make it work? I'm having this issue. I have this in my config.xml:

    <plugin name="cordova-plugin-media-capture" spec="~2.3.0">
        <variable name="CAMERA_USAGE_DESCRIPTION" value="(app name) would like to access your camera to let you take a new profile picture." />
        <variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="(app name) would like to access your photo library to let you select a profile picture." />
    </plugin>

And I tried doing:

cordova platform remove ios
cordova platform add ios
cordova build

But this is what ends up in my Info.plist:

    <key>NSCameraUsageDescription</key>
    <string/>
    <key>NSMicrophoneUsageDescription</key>
    <string/>
    <key>NSPhotoLibraryUsageDescription</key>
    <string/>
@benface

This comment has been minimized.

Copy link

benface commented Oct 10, 2016

Nevermind, I got this all wrong. I'm using a different plugin, cordova-plugin-media-capture. I actually removed it (as well as that snippet from my config.xml file) and re-added it with

cordova plugin add cordova-plugin-media-capture --variable CAMERA_USAGE_DESCRIPTION="(app name) would like to access your camera to let you take a new profile picture." --variable PHOTOLIBRARY_USAGE_DESCRIPTION="(app name) would like to access your photo library to let you select a profile picture."

And it worked.

@jcesarmobile

This comment has been minimized.

Copy link
Collaborator

jcesarmobile commented Oct 10, 2016

Just for your information, the "(app name) would like to access your camera" will be displayed by the system, don't repeat it again, you just have to add the reason why you want to access it.

@geoHeil

This comment has been minimized.

Copy link

geoHeil commented Oct 11, 2016

Indeed I got it to work after figuring out some caching issues.
jcesarmobile notifications@github.com schrieb am Di. 11. Okt. 2016 um
00:02:

Just for your information, the "(app name) would like to access your
camera" will be displayed by the system, don't repeat it again, you just
have to add the reason why you want to access it.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#270 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABnc9F7bZp9rM_OZjBmPVSdHwKuXgvP8ks5qyrX1gaJpZM4I_Mgj
.

@wmalevski

This comment has been minimized.

Copy link

wmalevski commented Jan 4, 2017

Hello is there a solution for Build Phonegap? I tried:

<plugin spec="https://github.com/phonegap/phonegap-plugin-barcodescanner.git#6.0.5" source="git">
    <param name="CAMERA_USAGE_DESCRIPTION" value="Some text here." />
    <param name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="Some text here." />
  </plugin>

Also I have tried:

  <config-file platform="ios" parent="NSCameraUsageDescription">
    <string>Some text here.</string>
  </config-file>

But still downloading and opening the IPA, I don't find any text, just empty strings.

@vendicto

This comment has been minimized.

Copy link

vendicto commented Jan 17, 2017

@wmalevski I have the same trouble. Does you resolve it ?

@wmalevski

This comment has been minimized.

Copy link

wmalevski commented Jan 17, 2017

hey @vendicto

I have found a solution myself, using:

  <gap:config-file platform="ios" parent="NSPhotoLibraryUsageDescription" overwrite="true">
    <string>We are using the Photo Library for something..</string>
  </gap:config-file>

This is specific for Build Phonegap.

good luck!

@vendicto

This comment has been minimized.

Copy link

vendicto commented Jan 17, 2017

@wmalevski, Thanks for answer but...
I tried your solution, added to the config in different places also added here: , but it still doesn't work, at the end I have plist file without "Privacy - Photo Library Usage Description"
You can see my question here http://stackoverflow.com/questions/41680639/nsphotolibraryusagedescription-doesnt-working-on-phonegap

@jcesarmobile

This comment has been minimized.

Copy link
Collaborator

jcesarmobile commented Jan 17, 2017

@vendicto the answer @wmalevski gave you is for building with phonegap build, config-file tag doesn't work on Cordova projects.
You have the values in the info.plist, so if they are removed when you archive, maybe you have found a bug, it they are there, the shouldn't disappear. Try creating the app with the Cordova CLI cordova build ios --device --release (you have to create and configure a build.json file first with your cert and provisioning profile information)

BTW, you don't have to add the "AppName would like to access xx", that will be displayed by the system, so it will appear twice, just add the reason why your app needs the camera.

@vendicto

This comment has been minimized.

Copy link

vendicto commented Jan 17, 2017

@jcesarmobile @wmalevski Thanks dudes.
@jcesarmobile I'll try to do like you said.
P.S I removed AppName from description, it was the old screen )

@Lestt

This comment has been minimized.

Copy link

Lestt commented Jan 24, 2017

Hi guys,

I tried the last vesion (6.0.5) and i still have this error concerning the PHOTOLIBRARY_USAGE_DESCRIPTION. I've removed the plugin, deleted the ios platform, added the plugin with this commande:
cordova plugin add phonegap-plugin-barcodescanner --variable CAMERA_USAGE_DESCRIPTION="My usage here" --variable PHOTOLIBRARY_USAGE_DESCRIPTION="My usage here"
I had to add the right manually in xcode.
Moreover, i looked into the plugin.xml file in the plugins directory (it's an ionic project so in my case plugins/phonegap-plugin-barcodescanner/plugin.xml), and there is no mention about PHOTOLIBRARY_USAGE_DESCRIPTION variable:

    <preference name="CAMERA_USAGE_DESCRIPTION" default=" "/>
    <config-file target="*-Info.plist" parent="NSCameraUsageDescription">
      <string>$CAMERA_USAGE_DESCRIPTION</string>
    </config-file>

Maybe that could help.

@jcesarmobile

This comment has been minimized.

Copy link
Collaborator

jcesarmobile commented Jan 24, 2017

@Lestt this plugin doesn't have the PHOTOLIBRARY_USAGE_DESCRIPTION, does it need it?

@Lestt

This comment has been minimized.

Copy link

Lestt commented Jan 24, 2017

@jcesarmobile I tried to upload my app to the store and i got this 2 error message from apple store:

Missing Info.plist key - This app attempts to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.

Missing Info.plist key - This app attempts to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data.

For this first one, i forgot to add the variable parameter on the command line when i added the plugin. As phonegap-plugin-barcodescanner is the one plugin that manipulate camera (and photo ?) in my porject, i suppose i had to add this right too ? I have no more informations from the store about this error. Let me know if i can help you more about it.
I am a newbie with ios environnement so i don't know how i can help you.

@jcesarmobile

This comment has been minimized.

Copy link
Collaborator

jcesarmobile commented Jan 24, 2017

It's strange because if you don't have the NSPhotoLibraryUsageDescription and you try to access the Photo Library it will crash, will take a look.
Maybe the encode function is writing/reading in/from the library and nobody noticed that it crash.

@jcesarmobile

This comment has been minimized.

Copy link
Collaborator

jcesarmobile commented Jan 24, 2017

Found the problem, I've created a new issue about it #406

@jcesarmobile

This comment has been minimized.

Copy link
Collaborator

jcesarmobile commented Jan 24, 2017

@Lestt I was wrong, there is no problem with the plugin, see my last comment on #406

You might have another plugin which is adding the NSPhotoLibraryUsageDescription

@vadimkrutovlv

This comment has been minimized.

Copy link

vadimkrutovlv commented Feb 1, 2017

Guys this solution worked for me. Just add description directly to your project projectName-info.plist file.
If you are using xcode, right click and open file as source code, at the bottom before
closing nodes insert following lines.

P.S Be careful with you description, otherwise apple can reject your binary from publishing to app store.

<key>NSCameraUsageDescription</key>
<string>Description</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Description</string>
@Lestt

This comment has been minimized.

Copy link

Lestt commented Feb 2, 2017

@jcesarmobile Ok, sry for pointing a non issue and waste your time :/

@jcesarmobile

This comment has been minimized.

Copy link
Collaborator

jcesarmobile commented Feb 2, 2017

@Lestt no problem

@Poliuk

This comment has been minimized.

Copy link

Poliuk commented Feb 9, 2017

This solved my problem

config.xml

    <plugin name="cordova-plugin-camera"              source="npm" >
      <variable name="CAMERA_USAGE_DESCRIPTION" value="Allow the app to use your camera" />
      <variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="Allow the app to access your photos" />
    </plugin>
    <plugin name="cordova-plugin-media-capture"       source="npm"  >
      <variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="Allow the app to access your photos" />
    </plugin>

I guess this hardcoded strings will be a problem in the future when it comes to support multiple languages in the App. Any advice?

@springcode

This comment has been minimized.

Copy link

springcode commented Feb 16, 2017

I solved it by adding the tags as suggested by @Poliuk and then removing and re-adding the plugin.

@ekambarrao

This comment has been minimized.

Copy link

ekambarrao commented May 15, 2017

Hi all, I have Visual Studio 2017 and used Cordova 7.0 and ios 8.3.1 and Mac 10.X. I am able to successfully build the solution and getting the ipa and plist. Now I am held up at publishing to store. It is giving error as
Missing Info.plist key - This app attempts to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.
and I have gone through all the link available and does all mentioned in several posts found it be not resolving the issue. Any suggestion? Note: I know that this not remotebuild issue to add here in this 'thread' but could not find a better place to mention about this than here.

Can somebody throw some light on this?

@springcode

This comment has been minimized.

Copy link

springcode commented May 15, 2017

Hi see the comments above regarding the config.xml in the root of your cordova build.

@ekambarrao

This comment has been minimized.

Copy link

ekambarrao commented May 15, 2017

@springcode I have used all those options. in *-info.plist inside Platform/ios/project folder, I can see all the values but it is failing at store validation.

@springcode

This comment has been minimized.

Copy link

springcode commented May 15, 2017

Its in the cordova config.xml in the root of your project not in the platform. You can also click on the plist in Xcode but this will get overwritten with each cordova build

@jcesarmobile

This comment has been minimized.

Copy link
Collaborator

jcesarmobile commented May 15, 2017

@ekambarrao you don't have to change the info.plist, you have to add the variables in the config.xml or provide such variables from VS2017 (if possible)

<plugin name="phonegap-plugin-barcodescanner" spec="~6.0.5">
        <variable name="CAMERA_USAGE_DESCRIPTION" value="To scan barcodes" />
</plugin>
@ekambarrao

This comment has been minimized.

Copy link

ekambarrao commented May 15, 2017

@springcode
@jcesarmobile

I understand. In that same Config.xml, I have added all of such tags inside config and they are reflecting in *-info.plist but still getting the same error.

@DanielNo

This comment has been minimized.

Copy link

DanielNo commented Jun 15, 2017

@Poliuk Your workaround worked for me thanks! Been struggling with this bug for a while

@joelnewcomer

This comment has been minimized.

Copy link

joelnewcomer commented Oct 11, 2017

I tried everything and the only solution for me was to uninstall and re-install the cordova-plugin-camera plugin.

@furkankatman

This comment has been minimized.

Copy link

furkankatman commented Oct 29, 2017

I spent a night on this and pulled my hair but at the end the solution for me was to add plugin with those params . with these params info plist changed in xcode and successfully uploaded app to test. cordova plugin add cordova-plugin-camera --variable CAMERA_USAGE_DESCRIPTION="your usage message" --variable PHOTOLIBRARY_USAGE_DESCRIPTION="your usage message"

@raghav-khunger

This comment has been minimized.

Copy link

raghav-khunger commented Dec 8, 2017

With the latest release the "ionic cordova build ios --release" is removing the values present inside PHOTOLIBRARY_USAGE_DESCRIPTION and CAMERA_USAGE_DESCRIPTION properties in this code:

<plugin name="cordova-plugin-camera" source="npm" > <variable name="CAMERA_USAGE_DESCRIPTION" value="Allow the app to use your camera" /> <variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="Allow the app to access your photos" /> </plugin>

The empty values can lead to following response while uploading the app to iTunes:

Dear developer,

We have discovered one or more issues with your recent delivery for "{Application Name}". To process your delivery, the following issues must be corrected:

Missing Info.plist key - This app attempts to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.

Once these issues have been corrected, you can then redeliver the corrected binary.

Regards,

The App Store team

Solution is to add the following code inside of <platform name="ios"> tag.

<config-file parent="NSPhotoLibraryUsageDescription" platform="ios" target="*-Info.plist"> <string>Allow the app to access your photos</string> </config-file> <config-file parent="NSCameraUsageDescription" platform="ios" target="*-Info.plist"> <string>Allow the app to use your camera</string> </config-file>

Here is the screenshot for the same:
image

After rebuilding the Ionic code it is no longer trimming the values present inside PHOTOLIBRARY_USAGE_DESCRIPTION property.

On rebuilding it is adding those two values at /platforms/ios/ios.json file

image

Further, it can verified under Info.plist:
image

You can see the above two values present there.

@raghav-khunger

This comment has been minimized.

Copy link

raghav-khunger commented Dec 10, 2017

I have provided another solution which you can opt while installing plugin.
https://stackoverflow.com/a/47736017/148657

@jcesarmobile

This comment has been minimized.

Copy link
Collaborator

jcesarmobile commented Dec 10, 2017

@raghav-khunger That answer is not good anymore, latest versions of cordova core plugins no longer use variables for the usage descriptions, you have to use edit-config tag

@vousys

This comment has been minimized.

Copy link

vousys commented Jan 25, 2018

First, this works for me with Cli-7.1.0 after apple reject me the ipa.

  1. In your code, if you use for ex. cordova-plugin-barcodescanner and cordova-plugin-camera and cordova-plugin-ios-camera-permissions all the variables CAMERA_USAGE_DESCRIPTION, PHOTOLIBRARY_USAGE_DESCRIPTION should have the same string inside. If one of them is different apple rejects your ipa, because phonegap use the default variable .

ej:


<plugin name="cordova-plugin-ios-camera-permissions" >
     <variable name="CAMERA_USAGE_DESCRIPTION" value="YOUR-PERMISSION-REQUEST" />
     <variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="YOUR-PERMISSION-REQUEST" />
</plugin><!-- spec="1.0.3" !-->

<plugin name="cordova-plugin-camera" > 
     <variable name="CAMERA_USAGE_DESCRIPTION" value="YOUR-PERMISSION-REQUEST" />
     <variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="YOUR-PERMISSION-REQUEST" />
<gap:plugin name="cordova-plugin-image-picker" source="npm" />
<gap:plugin name="cordova-plugin-base64-joewsh" source="npm" />   <!-- convertir a base64 los files !-->


<!-- barcode la v.0.7.2 tiene problemas, ojo !-->
<gap:plugin name="cordova-plugin-barcodescanner"   source="npm" spec="0.7.0" >

     <variable name="CAMERA_USAGE_DESCRIPTION" value="YOUR-PERMISSION-REQUEST" />
</gap:plugin>
  1. add this code (remember to use the same string in the variables, as I mention before):
<platform name="ios">

     <edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge" overwrite="true">
          <stringYOUR-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>
@lock

This comment has been minimized.

Copy link

lock bot commented Jun 7, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 7, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.