Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 418
Alex Reynolds Avatar asked Sep 15 '09 22:09

Alex Reynolds


People also ask

How do I regenerate info plist?

If you just want an empty info. plist file, then just select "New File..." on the "File" menu in XCode. In the "New File" window you pick "Other" on the left hand and then "Property List" on the right hand. Save this answer.

Where is info plist stored in an application?

The Info. plist file is by default located in the root folder of your application's bundle, it's derived from the {ProjectName}-Info. plist file in the Xcode project.

Why we use plist in Swift?

plist file. This plist contains information about your iOS project. It's distributed as part of your app's binary package, and iOS uses it for example to display your app's name on an iPhone's home screen.

What is Info plist file in iOS?

The Info. plist file contains critical information about the configuration of an iOS mobile app—such as iOS versions that are supported and device compatibility—which the operating system uses to interact with the app. This file is automatically created when the mobile app is compiled.


2 Answers

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.

like image 175
Ben Gottlieb Avatar answered Oct 03 '22 09:10

Ben Gottlieb


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.

like image 30
fbrereto Avatar answered Oct 03 '22 10:10

fbrereto