Last Updated: February 25, 2016
·
483
· widescape

Reading Info.plist configurations

After quite a long search how to access custom configurations in Info.plist I found Rod Wilhelmy's 'Environment variables in your RubyMotion project' with a nice example, which I copy here. But I missed some additional information, so here we go:

Rakefile

app.info_plist['ComYourAppFoo'] = 'Bar'

Mind, you have to repeat the scope "ComYourApp" for every custom configuration. And you'll have to repeat that scope for every call, too.

your_class.rb

foo = NSBundle.mainBundle.objectForInfoDictionaryKey('ComYourAppFoo')

Gosh, does that look ugly.

Thanks to Naming Convention

The reason for the ugliness? Keys should not collide with existing Apple keys, so better prefix them with "your app’s bundle ID or your company’s domain name" - see iOS Developer Library > Information Property List Key Reference > Custom Keys.

Clean up

Would be great to have Motion::Project::App.setup setter like app.info_plist_scoped[:foo] and a mainBundle getter like NSBundle.mainBundle.info_plist_scoped[:foo] that automatically does the scoping. But right now I haven't found a way to teach this to RubyMotion.