0

I have a requirement to display a different camera permissions message, one for when the user starts the QR scanner, and one for taking a photo.

The user can start with either one, and product don't want to use a generic message for both.

Is there a way to set NSCameraUsageDescription programmatically, or can this only be done within Info.plist?

Thanks

Rengers
  • 14,911
  • 1
  • 36
  • 54
thedp
  • 8,350
  • 16
  • 53
  • 95

3 Answers3

2

You can't edit the Info.plist of your app. You don't have write access to that file. In fact an app's bundle is read-only. You can't save changes to your bundle.

You should use a generic message mentioning both cases in the permission message. This way user knows that this permission will also be utilised in other places too.

thedp
  • 8,350
  • 16
  • 53
  • 95
Aakash
  • 2,239
  • 15
  • 23
1

As pointed out, .plist files cannot be edited at runtime. Anyways they can be localized. It's possible to create multiple Localizable.strings files containing different values for your NSCameraUsageDescription.

Right after, you could change the localization file your app is pointing to, obtaining the correct text that will be displayed in the alert.

  • I doubt if apple approves this :( – Aakash Nov 22 '18 at 09:44
  • Replacing localization strings at runtime is something that lots of applications do and there's nothing in the Developer Agreements that state such thing. That would be a totally viable approach :) – Lorenzo Zanotto Nov 22 '18 at 10:02
  • @LorenzoZanotto can you explain how to replace a localized InfoPlist.string my app is pointing to? thanks – thedp Nov 22 '18 at 10:06
  • I am concerned about apple and may be some users too might find out by doing this we are hiding out what our apps will exactly do with a permission. BTW I am also curious too know if this is feasible just for knowledge :) – Aakash Nov 22 '18 at 10:11
  • @thedp you can take a look here, it explains how to change the bundle you're reading from https://stackoverflow.com/questions/49649199/can-i-programatically-change-the-localizable-strings-file-on-button-click-with-o – Lorenzo Zanotto Nov 22 '18 at 10:17
  • @LorenzoZanotto It seems they just get the string from the desired `Localizable.strings` file, but I need to tell the system which `InfoPlist.strings` to use. Or am I missing something? – thedp Nov 22 '18 at 10:31
1

Besides the general message, you may present your customized alert message before request authorization somewhere, even with cooling animations.

E.Coms
  • 11,065
  • 2
  • 23
  • 35