The Toggle Switch in the settings bundle of iOS cannot get the value.
When setting the settings bundle of the App in Xcode7.2, it is found that when the bundle element type is Toggle Switch, the change value cannot be obtained in the App.
The Toggle Switch settings are as follows:
Read the value in the Code as follows:
BOOL isWarp = [defaults boolForKey:kWarpDrive];_warpDriveLabel.text = isWarp ? @"Engaged":@"Disabled";
KWarpDrive is defined as follows:
#define kWarpDrive @"warp"
It is strange that the status of the switch button is changed in settings and cannot be reflected in the App... Specifically, NO value is always read in the App regardless of the switch status.
The settings bundle of the App also has other types of elements, such as text or multi-choice columns. Other elements can normally read the changed values, but the Toggle Switch cannot.
Then, when the App is started, the corresponding value is registered:
+(void)regDefaultsFromSettingsBundle{ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSDictionary *dict = @{kWarpDrive:@(YES)}; [defaults registerDefaults:dict]; [defaults synchronize];}
Note that I only registered the value corresponding to kWarpDrive.
Then, the value changed by the switch can be read normally in the App. That's All !!!