我可以在应用程序运行时以编程方式翻转 Info.plist 值吗?
我有兴趣在我的应用程序中使用 SBUsesNetwork
和 UIRequiresPersistentWiFi
键;但是,我想仅在使用一组特定的视图控制器时启用它们。有没有办法在应用程序运行时以编程方式翻转这些键值?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您无法在运行时修改捆绑包内容,您没有对该目录的写入权限。我不确定是否有一种方法可以完全满足您的要求。
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.
我知道你可以通过 NSBundle 具有以下内容:
从那里您可以创建
NSDictionary
的mutableCopy
并在其中设置值。当查询键时,您必须确保查询 NSDictionary 而不是 info.plist 文件,但将所有这些封装到一个处理这两者的类中应该不难给你带来问题。至于直接修改应用程序的 info.plist 文件,可能会出现问题(例如,如果修改文件,代码签名将失败,并且您的应用程序将被视为已损坏),尽管我对此不确定。
I know you can get your info.plist as an NSDictionary via NSBundle with the following:
from there you could make a
mutableCopy
of theNSDictionary
and set the values therein. When making queries to the keys you'll have to make sure to query theNSDictionary
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.
您无法修改 Info.plist。似乎没有苹果认可的方式来做你所追求的事情。
You cannot modify the Info.plist. There does not seem to be an Apple sanctioned way of doing what you are after.
我认为这行不通。 [NSBundle mainBundle] 有一个指向特定 infoDictionary 的指针。即使你获取了一个可变的副本,NSBundle 也不知道我们的新 plist 的任何信息。有人尝试过吗?
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?
Info.plist只不过是一本字典。因此可以对其进行编辑。
Info.plist is nothing but a dictionary. Hence it can be edited.