iOS Tutorial Adding your settings to the default Settings app

Discussion in 'iOS Tutorials' started by Erel, Dec 30, 2014.

  1. Erel

    Erel Administrator Staff Member Licensed User

    By following the steps in this tutorial you can allow users to configure the various app settings in the default Settings app.

    [​IMG]

    The settings are defined in one or more plist files (xml files). The files should be located under Files\Special\Settings.bundle.

    The main settings file name is Root.plist:

    [​IMG]

    You can use the SettingsCreator desktop application (written with B4J) to create these files:

    [​IMG]

    The plist format is documented here: https://developer.apple.com/library...ction.html#//apple_ref/doc/uid/TP40007005-SW1

    The SettingsCreator application is quite simple. Right click on the list to add new items.

    B4i code

    The Settings object from iPhone library (v1.20+) allows you to get or set the settings.
    Each setting is made of a key and value. Similar to Maps.
    You need to declare and initialize a Settings object and then you can get or put values:
    Code:
    Dim set As Settings
    set.Initialize
    Dim Toggle1 As Boolean = set.GetBoolean("ts1")
    set.Put(
    "sr1"50)
    Note that you can also create new keys (which will not be visible in the settings app).

    The modified settings are saved automatically from time to time. You can call Settings.Synchronize to force the changes to be saved immediately.

    The compiled settings creator utility is attached. The source code is available here: http://www.b4x.com/android/forum/threads/ios-settingscreator.48779/
     

    Attached Files:

    Last edited: Dec 30, 2014
    MikeH, Peter Simpson, imbault and 5 others like this.
  2. Erel

    Erel Administrator Staff Member Licensed User

    A few words about the elements:

    - Group - Separates the settings into multiple groups.
    - MultiValue - Allows the user to select a single item from a list of items. The items are listed in a different page. Each item is made of a title and value. The user only sees the titles.
    - RadioGroup - Similar to MultiValue. The items are listed in the main page.
    - Slider - Standard slider.
    - TextField - Standard TextField. Note that there is no way to close the keyboard except of moving to a different page.
    - ToggleSwitch - A standard Switch
    - ChildPane - Allows the user to move to a different settings page. The file value should be the plist file name without the extension.
     
  3. little3399

    little3399 Active Member Licensed User

    Hi, Erel

    Is this function can be using for B4A ? tks!
     
  4. Eumel

    Eumel Active Member Licensed User

    This is for B4i

    Look for PreferenceActivity or AHPreferenceActivity in the B4A Forums.
     
  5. schimanski

    schimanski Well-Known Member Licensed User

    Two questions:

    1. Is it possible to show the settings out of the own app?

    2. Is it possible to read the settings out on a desktop-pc? My idea is to save also the password of my app in a nonvisible field.

    Happy new year....
     
  6. Eric Baker

    Eric Baker Member Licensed User

    Does this work on iPads too?

    Updated iPhone Library to 1.2 and tried unmodified example and get this:

    Code:
    Application_Start
    Error occurred on line: 
    26 (main)
    Cannot 
    parse: (null)
    Stack Trace: (
      CoreFoundation  <redacted> + 
    150
      libobjc.A.dylib  objc_exception_throw + 
    38
      CoreFoundation  <redacted> + 
    0
      B4i Example  -[B4I ObjectToNumber:] + 
    556
      B4i Example  -[B4ISettings GetInt:] + 
    114
      B4i Example  -[b4i_main _application_start:] + 
    2042
      CoreFoundation  <redacted> + 
    68
      CoreFoundation  <redacted> + 
    300
      B4i Example  +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 
    1928
      B4i Example  -[B4IShell runMethod:] + 
    496
     B4i Example  -[B4IShell raiseEventImpl:method:args::] + 
    1846
     B4i Example  -[B4IShellBI raiseEvent:
    event:params:] + 1316
     B4i Example  __
    33-[B4I raiseUIEvent:event:params:]_block_invoke + 74
     libdispatch.dylib  <redacted> + 
    10
     libdispatch.dylib  <redacted> + 
    22
     libdispatch.dylib  <redacted> + 
    712
     CoreFoundation  <redacted> + 
    8
     CoreFoundation  <redacted> + 
    1512
     CoreFoundation  CFRunLoopRunSpecific + 
    476
     CoreFoundation  CFRunLoopRunInMode + 
    106
     GraphicsServices  GSEventRunModal + 
    136
     UIKit  UIApplicationMain + 
    1440
     B4i Example  main + 
    116
     libdyld.dylib  <redacted> + 
    2
    )
    Also, I do net see any settings available in setup.
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    1. The settings declared in the plist file are visible in the Settings app. Other settings will not be visible.
    2. The settings are stored in a file under the Library folder. iTunes doesn't provide access to this folder.
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Yes:
    [​IMG]

    The error you are getting is because the settings were not created for some reason so it fails to parse the number from the settings.

    Are you using B4i v1.50?
     
  9. Eric Baker

    Eric Baker Member Licensed User

    Yes, I am using v1.50 with iPhone lib ver. 1.20

    B4I Example does show up in settings, but the settings page is completely empty.

    Using iPad2 with IOS 8.1.2

    I made sure I deleted all previous old B4I examples on device, rebooted iPad, cleaned project, recompiled -- same result, same error
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    Have you tried to restart the device?
     
    Simon Smith likes this.
  11. Simon Smith

    Simon Smith Active Member Licensed User

    Thanks for that. So delete the plist and you delete the settings? The compiled settings app looks good
     
  12. Eric Baker

    Eric Baker Member Licensed User

    Yes, restarted the device. Even renamed the project and package name.

    I commented out line 26 to see what happens. Line 27 runs without error, but the settings page is still empty.

    Using xCode 6.1, if that makes a difference, I could try to build it on remote if you can give me access to test this.
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    The settings should appear even if you don't run the app.

    Try this, compile your app and then download the ipa file (Tools - Build Server - Download last build).

    Open the ipa file with a zip tool such as 7zip:

    [​IMG]

    See whether the plist files are there.
     
  14. Eric Baker

    Eric Baker Member Licensed User

    Yes, they are there. I will borrow my son's iPhone and see if it works there.
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    I've sent you a temporary user id for the hosted builder. Test it with the hosted builder.
     
  16. Eric Baker

    Eric Baker Member Licensed User

    Badabing Boom shakalaka!! It works.

    I am using Xcode Version 6.1.1 (6A2008a).

    I'll reinstall the local builder and see what happens.
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    It probably happens because you are not using a real mac.

    I recommend you to switch to the hosted builder. It is simple and reliable.
     
  18. Eric Baker

    Eric Baker Member Licensed User

    I doubt it. Had the same issue using my macbook air as a build server. The difference between a cloned mac and the real thing is usually only at the kernel level, requiring drivers for some non mac hardware. I run stock everything except for sound. But that discussion does not belong here.


    Yes, now that I got to give it a test, I actually like it. Its pretty slick. Two thumbs up! I can highly recommend it also and will subscribe to it as I plan to travel next month and only want to take a cheap (windows) laptop with me. I wonder how well it works on a fairly slow connection (maybe 512 kbit) , as I will be roaming around in south east asia.

    UPDATE

    Installed the latest beta, and the settings example works here on the macbook air and the hackintosh as a build server. Not sure if you changed something, or I installed the libs incorrectly, or my completely deleting b4i and reinstalling did the trick.

    Thanks Erel
     
  19. aaronk

    aaronk Well-Known Member Licensed User

    Just a heads up for anyone that uses the SettingsCreator from post 1, when you save the file make sure it saves the file as '.plist' and not as 'file'.
    I found that I needed to add '.plist' to the end of the filename such as 'Root.plist' as it saved as 'Root.file'.
     
  20. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    Hi Erel.
    It's very good thank you and good luck
     
Loading...