iosxamarinxamarin.iosinfo.plistproperty-list

Enumerate UISupportedExternalAccessoryProtocols at runtime


I'm using Xamarin.iOS to wrap an Objective-C library for an accessory that connects to iPods and iPhones via the dock connector. I wasted a lot of time trying to get the accessory to work in my test app before I discovered that I was missing values under UISupportedExternalAccessoryProtocols in Info.plist in my test app.

I'd like to prevent others from running into the same problem when they use my wrapper library. Since this is a library, I can't have an Info.plist in my project, right? So I'd like to enumerate the values the caller has for UISupportedExternalAccessoryProtocols so I can give an easy to read message to developers that they're missing values. Is there a way to do this at run time?

Thanks!


Solution

  • Either of these will work to access values in the Info.plist:

        var protocolArray = (NSArray)NSBundle.MainBundle.InfoDictionary ["UISupportedExternalAccessoryProtocols"];
    

    Or

        var protocolArray = (NSArray)NSBundle.MainBundle.ObjectForInfoDictionary ("UISupportedExternalAccessoryProtocols");
    

    then get the values like so:

            for (nuint i = 0; i < protocolArray.Count; i++) {
                Console.Write (protocolArray.GetItem<NSString> (i).ToString ());
            }