Can i modify Root.plist in settings bundle dynamically?
Asked Answered
E

2

8

I have a settings bundle in my app.. containing root.plist now i have a screen which contains a checkbox.. on pressing the check box i want to change the BOOL value for DefaultValue key of PSToggleSwitchSpecifier in the plist. Since its being done at runtime.. my question is that .. can the file be changed at runtime and if yes.. give an idea how to do it??

here is the plist:

    <plist version="1.0">
<dict>
    <key>PreferenceSpecifiers</key>
    <array>
        <dict>
            <key>DefaultValue</key>
            <string></string>
            <key>Key</key>
            <string>Username</string>
            <key>Title</key>
            <string>Username</string>
            <key>Type</key>
            <string>PSTextFieldSpecifier</string>
        </dict>
        <dict>
            <key>DefaultValue</key>
            <string></string>
            <key>IsSecure</key>
            <true/>
            <key>Key</key>
            <string>Password</string>
            <key>Title</key>
            <string>Password</string>
            <key>Type</key>
            <string>PSTextFieldSpecifier</string>
        </dict>
        <dict>
            <key>Type</key>
            <string>PSToggleSwitchSpecifier</string>    <-----toggleSwitch
            <key>Title</key>
            <string>Remember</string>
            <key>Key</key>
            <string>CheckBox</string>
            <key>DefaultValue</key>    <----- Default Value
            <false/>                   <---- want to change this value 
        </dict>
    </array>
    <key>Title</key>
    <string>Settings</string>
</dict>
</plist>

thank you in advance ;)

Estheresthesia answered 4/8, 2011 at 12:18 Comment(5)
Theres a blog post for the same here.Camire
this is not for root.plist i guessEstheresthesia
Yup thats right. As Joshua has suggested you cant modify files from application bundle. I hope the above link helps you.Camire
- you can modify files from the application bundle, if you have a jailbroken iOS device, and your app is running from within the /Applications directoryRockribbed
Hey @Estheresthesia did you find issue for your problem?Cingulum
R
11

Because the settings bundle resides inside your app's bundle, you cannot change it at runtime, only at compile-time.

You can, however, use NSUserDefaults to set the value at runtime, and the settings application will automatically reflect this. It will be saved elsewhere, though. You can just read it back the same way as you would do with the settings bundle, also through NSUserDefaults.

Note that you shouldn't read from the settings bundle directly, as it makes no sense. You should always fetch and set user defaults using NSUserDefaults. When the user makes a change in the settings application, NSUserDefaults will reflect this automatically. They will always be kept in sync.

Ree answered 4/8, 2011 at 12:26 Comment(1)
Can you please tell how to write into Settings bundle root.plist using NSUserDefaults? I am able to read the file, and I want to update the modification done in app into Root.plist in Settings bundle.Georgena
R
2

You can not modify files with the application bundle..

Rhombohedron answered 4/8, 2011 at 12:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.