我可以在应用程序运行时以编程方式翻转 Info.plist 值吗?

发布于 2024-08-05 01:18:16 字数 141 浏览 5 评论 0原文

我有兴趣在我的应用程序中使用 SBUsesNetworkUIRequiresPersistentWiFi 键;但是,我想仅在使用一组特定的视图控制器时启用它们。有没有办法在应用程序运行时以编程方式翻转这些键值?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

一枫情书 2024-08-12 01:18:16

您无法在运行时修改捆绑包内容,您没有对该目录的写入权限。我不确定是否有一种方法可以完全满足您的要求。

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.

一页 2024-08-12 01:18:16

我知道你可以通过 NSBundle 具有以下内容:

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

从那里您可以创建 NSDictionarymutableCopy 并在其中设置值。当查询键时,您必须确保查询 NSDictionary 而不是 info.plist 文件,但将所有这些封装到一个处理这两者的类中应该不难给你带来问题。

至于直接修改应用程序的 info.plist 文件,可能会出现问题(例如,如果修改文件,代码签名将失败,并且您的应用程序将被视为已损坏),尽管我对此不确定。

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.

心安伴我暖 2024-08-12 01:18:16

您无法修改 Info.plist。似乎没有苹果认可的方式来做你所追求的事情。

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

难得心□动 2024-08-12 01:18:16

我认为这行不通。 [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?

对岸观火 2024-08-12 01:18:16

Info.plist只不过是一本字典。因此可以对其进行编辑。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文