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

大憨熊 提交于 2020-01-13 10:03:11

问题


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?


回答1:


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.




回答2:


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.




回答3:


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




回答4:


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?




回答5:


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



来源:https://stackoverflow.com/questions/1429886/can-i-programmatically-flip-info-plist-values-while-my-application-is-running

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!