Implementing iOS Setting Bundle - Blogs

Implementing iOS Setting Bundle

 iOS Setting Bundle:-

Actually sometimes we need to interact our app i.e giving some input value or changing some default value or use default value unless we are not changing that value  in  that case we need to create one app setting which will be outside the app but once we click on Setting in device we can navigate to Setting panel  where we can get out app and we modify something there.Once we will come back to our app after Setting screen , can see the change .So here there are two major things first how to create Setting Bundle and then how to read the Setting Bundle value in our app (app delegate).

First we are going to see how to create Setting Bundle and what are all types of control which we can create in Setting bundle:-
Control type
Text field
The text field type displays a title (optional) and an editable text field. You can use this type for preferences that require the user to specify a custom string value.
The key for this type is PSTextFieldSpecifier.
The title type displays a read-only string value. You can use this type to display read-only preference values. (If the preference contains cryptic or nonintuitive values, this type lets you map the possible values to custom strings.)
The key for this type is PSTitleValueSpecifier.
Toggle switch
The toggle switch type displays an ON/OFF toggle button. You can use this type to configure a preference that can have only one of two values. Although you typically use this type to represent preferences containing Boolean values, you can also use it with preferences containing non-Boolean values.
The key for this type is PSToggleSwitchSpecifier.
The slider type displays a slider control. You can use this type for a preference that represents a range of values. The value for this type is a real number whose minimum and maximum value you specify.
The key for this type is PSSliderSpecifier.
The multivalue type lets the user select one value from a list of values. You can use this type for a preference that supports a set of mutually exclusive values. The values can be of any type.
The key for this type is PSMultiValueSpecifier.
The group type is for organizing groups of preferences on a single page. The group type does not represent a configurable preference. It simply contains a title string that is displayed immediately before one or more configurable preferences.
The key for this type is PSGroupSpecifier.
Child pane
The child pane type lets the user navigate to a new page of preferences. You use this type to implement hierarchical preferences. For more information on how you configure and use this preference type.
The key for this type is PSChildPaneSpecifier.
Here we are going to see an example where we are creating one input field as textfield and setting some default value.
This is format of Root.plist file 




        Here we can give our app name


















                Here we can set the default value




































So now we are done with Root,plist file.It's time to create one empty folder and put this Root.plist file in that,after that change the name of folder as Settings.bundle,while changing name you will be getting this  message prompt,please click on Add and then go ahead.
After Click on Add we will get our Settings.bundle like this:-
Now we are done with Settings.bundle ,please add this to project just drag and drop into project.After running app when we will navigate into Setting screen we can get our app setting something like this.In this example i have created one app TestApp setting which is appearing like this.
Here we are going to see how to read default(if any) value or entered value from Setting bundle

NSString *kFirstNameKey= @"name_p_preference";

//for reading default value for Terminal
    NSString *testValue = [[NSUserDefaults standardUserDefaultsstringForKey:kFirstNameKey];
if (testValue == nil)
// no default values have been set, create them here based on what's in our Settings bundle info
NSString *pathStr = [[NSBundle mainBundlebundlePath];
NSString *settingsBundlePath = [pathStr stringByAppendingPathComponent:@"Settings.bundle"];
NSString *finalPath = [settingsBundlePath stringByAppendingPathComponent:@"Root.plist"];
NSDictionary *settingsDict = [NSDictionary dictionaryWithContentsOfFile:finalPath];
NSArray *prefSpecifierArray = [settingsDict objectForKey:@"PreferenceSpecifiers"];


NSString *firstNameDefault = nil;
NSDictionary *prefItem;
for (prefItem in prefSpecifierArray)
NSString *keyValueStr = [prefItem objectForKey:@"Key"];
id defaultValue = [prefItem objectForKey:@"DefaultValue"];


if ([keyValueStr isEqualToString:kFirstNameKey])
firstNameDefault = defaultValue;


// since no default values have been set (i.e. no preferences file created), create it here

        NSString *defaultterminalval = [[NSUserDefaults standardUserDefaultsstringForKey:kFirstNameKey];

       //here we can store this defaultterminalval to use somewhere else as per our need
        [[NSUserDefaults standardUserDefaults]setObject:defaultterminalval forKey:@"TerminalTimeOut"];


        NSString *getterminaltimeout=[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaultsvalueForKey:@"name_p_preference"]];
   //in this block we are reading the value which has been entered from setting screen



Access Control in Swift 3

End of this blog you will be able to understand the Access control specifiers open, public,internal,...

Read More >

How to handle the exceptions using recovery scenario manager in QTP?

VB script Error HandlingDurning run time, if QTP encounters any erorr then it will display the error...

Read More >

Creating Apps Using Phonegap Framework in IOS

Creating apps for different operating system is not a reliability so for reducing developr work for ...

Read More >

Memory Management in iOS

Memory Management iOS In this blog we will walk through very important thing which all iOS developer...

Read More >

Base64 encoding in Objective c

When we have some binary data that need to send across network, we generally don't do it by just...

Read More >

Wireless Ad-Hoc distribution for iOS apps

Creating Ad-Hoc is an important part of iOS app development because it helps us in testing the app d...

Read More >

iOS qrcode generator

Have you heard of QR Codes yet? Here is a quick introduction:- QR is short for Quick Response . It i...

Read More >

How to Create a Provisioning profile for iOS

To Run an app on iOS device,you must have a Provisioning Profile installed on your device. ...

Read More >

How to check network reachability in iOS

What is network reachability? Now, you are all set to program your app on the ios device? Here is on...

Read More >


Try DevOpSmartBoard Ultimate complete Azure DevOps End-to end reporting tool

Sign Up

  • Recent
  • Popular
  • Tag
Monthly Archive

Contact Us
  • *
  • *