phonegap / phonegap-plugin-barcodescanner

cross-platform BarcodeScanner for Cordova / PhoneGap
MIT License
1.27k stars 1.42k forks source link

iOS 10 requires Camera permission reason #270

Closed EddyVerbruggen closed 8 years ago

EddyVerbruggen commented 8 years ago

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 commented 8 years ago

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

EddyVerbruggen commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

@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 commented 8 years ago

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. https://github.com/apache/cordova-plugin-contacts/pull/131

jcesarmobile commented 8 years ago

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 commented 8 years ago

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

jcesarmobile commented 8 years ago

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

jcesarmobile commented 8 years ago

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 commented 8 years ago

@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 commented 8 years ago

Yes, it looks good, closing.

michaljakubowski commented 8 years ago

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

geoHeil commented 8 years ago

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 commented 8 years ago

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

geoHeil commented 8 years ago

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 https://github.com/phonegap/phonegap-plugin-barcodescanner/issues/270#issuecomment-250699236, or mute the thread https://github.com/notifications/unsubscribe-auth/ABnc9II6gchdrF_dL6lNS13VlKHesGH2ks5qvNR9gaJpZM4I_Mgj .

jcesarmobile commented 8 years ago

Try removing platforms and plugins folders and adding ios platform again

Also, for photo library is PHOTOLIBRARY_USAGE_DESCRIPTION, not NSPHOTOLIBRARYUSAGEDESCRIPTIONENTRY

pke commented 8 years ago

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 commented 8 years ago

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

jcesarmobile commented 8 years ago

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 commented 8 years ago

@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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 https://github.com/phonegap/phonegap-plugin-barcodescanner/issues/270#issuecomment-252758054, or mute the thread https://github.com/notifications/unsubscribe-auth/ABnc9F7bZp9rM_OZjBmPVSdHwKuXgvP8ks5qyrX1gaJpZM4I_Mgj .

wmalevski commented 7 years ago

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 commented 7 years ago

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

wmalevski commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

@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 commented 7 years ago

@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 commented 7 years ago

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_USAGEDESCRIPTION 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 commented 7 years ago

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

Lestt commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

Found the problem, I've created a new issue about it https://github.com/phonegap/phonegap-plugin-barcodescanner/issues/406

jcesarmobile commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

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

jcesarmobile commented 7 years ago

@Lestt no problem

Poliuk commented 7 years ago

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 commented 7 years ago

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

ekambarrao commented 7 years ago

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 commented 7 years ago

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

ekambarrao commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

@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 commented 7 years ago

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

joelnewcomer commented 7 years ago

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

furkankatman commented 7 years ago

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-axero commented 6 years ago

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:

`

  <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.

`

Allow the app to access your photos
    </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.