Question

I've been trying to setup settings for my app but I can't seem to get this working even though I've looked over it over and over again and compared it to an example in a book and the example on Craig Dunn's blog.

I understand that the syntax has to be perfect and this file is pretty simple at the moment I am just trying to display one textfield for now. I did get this working briefly on a brand new project however I haven't managed to get it to work since.

Here is the XML of my Root.plist file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Root</key>
<dict>
    <key>PreferenceSpecifiers</key>
    <array>
        <dict>
            <key>Title</key>
            <string>Group Name</string>
            <key>Type</key>
            <string>PSGroupSpecifier</string>
        </dict>
        <dict>
            <key>AutocapitalizationType</key>
            <string>None</string>
            <key>AutocorrectionType</key>
            <string>No</string>
            <key>Key</key>
            <string>usernameTextField</string>
            <key>Title</key>
            <string>Username</string>
            <key>Type</key>
            <string>PSTextFieldSpecifier</string>
        </dict>
    </array>
</dict>
</dict>
</plist>

As I said I've looked over it quite a lot of times and I can't see any problems with it. The file build action is set to Content and the Copy to Output Directory is set to Always Copy. The version of MonoTouch that I'm using is 6.0.7.

I'd appreciate any help with this issue. Thanks

Was it helpful?

Solution

  1. Make sure that the Settings.bundle directory is included at the top level of the project. By top-level, I mean that on the file system, the Settings.bundle directory should be in the same directory as your ProjectName.csproj file. In MonoDevelop, it will appear as one of the top-level folders under the project node.

  2. Set the Root.plist Build Action to BundleResource (do not enable "Copy to Output Directory". Hint: if you find yourself setting "Copy to Output Directory", don't do it - it's almost always the wrong thing to do - we've actually discussed removing the option altogether.)

Now, for the plist file format - here's what it should look like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>PreferenceSpecifiers</key>
    <array>
        <dict>
            <key>Type</key>
            <string>PSGroupSpecifier</string>
            <key>Title</key>
            <string>Group Name</string>
        </dict>
        <dict>
            <key>Type</key>
            <string>PSTextFieldSpecifier</string>
            <key>Title</key>
            <string>Username</string>
            <key>AutocapitalizationType</key>
            <string>None</string>
            <key>AutocorrectionType</key>
            <string>No</string>
            <key>KeyboardType</key>
            <string>Alphabet</string>
            <key>IsSecure</key>
            <false/>
            <key>Key</key>
            <string>usernameTextField</string>
            <key>DefaultValue</key>
            <string></string>
        </dict>
    </array>
    <key>StringsTable</key>
    <string>Root</string>
</dict>
</plist>

Looking at your Root.plist file, it appears that the PreferenceSpecifiers key is not in the top-level dict node (it needs to be). In other words:

get rid of the following lines at the top of the file:

<dict>
<key>Root</key>

...and one of the following lines at the end of your file:

</dict>

That should do it...

Now... all that said, I just recently figured this out myself while trying to add settings to my personal side project and decided that we, at Xamarin, need to make this easier. I've already fixed a few minor issues in the upcoming MonoDevelop 3.1, but I hope to get the time I need to add templates for Settings.bundle to MonoDevelop's "Add New File" wizard. I'd also like to add plist key/value hinting like we do for Info.plist and Entitlements.plist so that MonoDevelop's plist editor can better guide you when editing these plist files.

OTHER TIPS

For starters, you are missing your closing plist </plist> tag. My current one only has one setting in it, but it works. You can compare to yours to see the differences:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" 
    "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>PreferenceSpecifiers</key>
  <array>
      <dict>
          <key>Type</key>
          <string>PSToggleSwitchSpecifier</string>
          <key>Title</key>
          <string>Stay Signed-In</string>
          <key>Key</key>
          <string>staySignedIn</string>
          <key>DefaultValue</key>
          <true/>
      </dict>
    </array>
</dict>
</plist>

I hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top