iOS Tutorial Adding your settings to the default Settings app

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

SS-2014-12-30_12.28.50.png


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:

SS-2014-12-30_12.34.01.png


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

SS-2014-12-30_12.35.41.png


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:
B4X:
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: https://www.b4x.com/android/forum/threads/ios-settingscreator.48779/
 

Attachments

  • SettingsCreator.jar
    246.5 KB · Views: 778
  • SettingsExample.zip
    2 KB · Views: 815
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime 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.
 

Eumel

Active Member
Licensed User
Longtime User
This is for B4i

Look for PreferenceActivity or AHPreferenceActivity in the B4A Forums.
 

schimanski

Well-Known Member
Licensed User
Longtime 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....
 

Eric Baker

Member
Licensed User
Longtime User
Does this work on iPads too?

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

B4X:
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.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
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.

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.
 

Eric Baker

Member
Licensed User
Longtime 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
 

Simon Smith

Active Member
Licensed User
Longtime User
Thanks for that. So delete the plist and you delete the settings? The compiled settings app looks good
 

Eric Baker

Member
Licensed User
Longtime User
Have you tried to restart the device?
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.
 

Eric Baker

Member
Licensed User
Longtime User
I've sent you a temporary user id for the hosted builder. Test it with the hosted builder.

Badabing Boom shakalaka!! It works.

I am using Xcode Version 6.1.1 (6A2008a).

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

Eric Baker

Member
Licensed User
Longtime User
It probably happens because you are not using a real mac.

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.

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


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
 

aaronk

Well-Known Member
Licensed User
Longtime 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'.
 
Top