Can I programmatically flip Info.plist values while my application is running?
Asked Answered
I

5

5

I am interested in using the SBUsesNetwork and UIRequiresPersistentWiFi keys in my application; however, I would like to enable them only when using a certain set of view controllers. Is there a way to programmatically flip those key values while the application is running?

Icecap answered 15/9, 2009 at 22:9 Comment(0)
V
6

You can't modify your bundle contents while running, you don't have write access to that directory. I'm not sure there's a way to do exactly what you want.

Volnay answered 16/9, 2009 at 0:50 Comment(0)
W
3

I know you can get your info.plist as an NSDictionary via NSBundle with the following:

NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];

from there you could make a mutableCopy of the NSDictionary and set the values therein. When making queries to the keys you'll have to make sure to query the NSDictionary and not your info.plist file, but it shouldn't be hard to encapsulate all of this into a class that handles both problems for you.

As for modifying your app's info.plist file directly there could be issues there (e.g, if you modify the file the code signing will fail and your app will be considered corrupt), though I'm not certain on this.

Whistle answered 15/9, 2009 at 22:25 Comment(2)
The UIRequiresPersistentWiFi key seems to hook into some larger UIApplication code I cannot or do not know how access, which presents a WiFi dialog box when a network connection is needed. Therefore, making a copy of the bundle preferences may not get me far in this particular case, although this might be applicable for other keys, if their behavior can be overriden.Icecap
You won't be able to change your info.plist or any of the files in you mainbundle.Baroscope
P
0

You cannot modify the Info.plist. There does not seem to be an Apple sanctioned way of doing what you are after.

Pga answered 17/9, 2009 at 12:13 Comment(0)
P
0

I don't think this will work. [NSBundle mainBundle] has a pointer to a specific infoDictionary. Even though you take a mutable copy, NSBundle wouldn't know anything about our new plist. Anyone tried yet?

Perceval answered 26/12, 2009 at 3:43 Comment(0)
R
0

Info.plist is nothing but a dictionary. Hence it can be edited.

Redouble answered 19/2, 2013 at 5:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.