17

I need to add keys to the info plist but there is no way to open the file for editing. The xamarin docs state that there should be 3 tabs , one of them being source, which let me manually add keys. Where is that tab?

Rob8861
  • 433
  • 1
  • 4
  • 14
  • 1
    You can always open the file in a simple text editor if you need to do manual editing. Otherwise you can see our docs on this topic: https://developer.xamarin.com/guides/ios/application_fundamentals/working_with_property_lists/#Info.plist – Jon Douglas Aug 17 '16 at 17:23
  • 2
    I am aware of the docs but my point was that they do not apply to visual studio. Asking VS users to edit the file with a simple text editor, is providing bad user experience. How would I know that the changes I made manually will not get overridden by VS. – Rob8861 Aug 17 '16 at 18:29

4 Answers4

27

In visual studio 2017 for Windows

  1. Right click on Info.plist and select "Open With"

    enter image description here

  2. Select "Generic Plist Editor" from the programs list

    enter image description here

  3. Can add/edit keys

    enter image description here

rsssssonsss
  • 413
  • 5
  • 6
4

You get the 3 tabs when you are editing the info.Plist in the Xamarin Studio. Below is the screen shot from mac.

Screen shot from Xamarin Studio on Mac

Here is the source tab in which you could manually add keys and it would be converted to corresponding tags.

Source tab

There is no problem in manually editing the info.Plist manually by using a text editor of your choice.

Rohit Vipin Mathews
  • 11,629
  • 15
  • 57
  • 112
  • 3
    I am aware of that. That was not my argument here. The issue is that Xamarin provides different user experience and tools for users who choose to develop in visual studio. that is inconsistency and I don't like inconsistencies, especially in software development. – Rob8861 Aug 18 '16 at 16:00
3

In Visual Studio at the time being you can open info.plist with any editor and add your keys between the <dict> </dict> tags. An example for camera and gallery permisions:

...
<dict>
...
    <key>NSCameraUsageDescription</key>
    <string>Message for permission to access camera</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>Message for permission to access gallery</string>
...
</dict>
...

More permissions and details here https://blog.xamarin.com/new-ios-10-privacy-permission-settings/

2

I also had issues adding keys to plist.info file inside Visual Studio, but I managed it eventually.

It can be problematic, as the App Properties do not seem to contain any area for adding keys, and manual changes to the file can get overwritten by the App Properties when it is closed or saved.

The only reliable way I have found to add keys to plist.info (in Visual Studio) is as follows...

1) Make sure the App Properties are saved and closed (the designer window must NOT be open).

2) Right click the file in Solution Explorer, and choose 'View Code'.

3) Manually edit the XML to add the new key(s) and associated data entry to the end of the file as shown in this example...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        ...
        <key>NSCalendarsUsageDescription</key>
        <string>This app needs access to your calendar.</string>
        <key>NSPhotoLibraryUsageDescription</key>
        <string>This app needs access to your photos.</string>
    </dict>
</plist>

4) Save and close the window before any re-opening of App Properties.

If you follow the above steps, subsequent opening the App Properties and making changes should not overwrite your new keys in plist.info. BUT... it's probably a good idea to keep a copy of the new keys in another file (I use plist.info.keys) just in-case.

controlbox
  • 522
  • 4
  • 13