ios 8.2 and above settings bundle is not showing selected item but Default

爱⌒轻易说出口 提交于 2019-12-10 12:30:03

问题


I am facing a issue with App settings, i am using settings bundle to select the environment, but once selected and going back to app settings its showing again the default one as selected.

This is observed only from ios 8.2 and above(Device and simulator). My settings bundle plist looks like below.

<?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>DefaultValue</key>
            <string>1</string>
            <key>Key</key>
            <string>Environment</string>
            <key>Title</key>
            <string>Environment</string>
            <key>Titles</key>
            <array>
                <string>Live</string>
                <string>Stage</string>
            </array>
            <key>Type</key>
            <string>PSRadioGroupSpecifier</string>
            <key>Values</key>
            <array>
                <string>0</string>
                <string>1</string>
            </array>
        </dict>
    </array>
    <key>StringsTable</key>
    <string>Root</string>
</dict>
</plist>

I already see some info in Stack overflow that this is existing bug from Apple, I hope if some one has any any update on it.


回答1:


If your apperance settings are set during launch, you must reload your app viewcontrollers to display the change, so you could add to your appDelegate something like:

NSString *type in your ivars

then

type = [[NSUserDefaults standardUserDefault] objectForKey:@"Your key"];

in your didFinishLaunchingWithOptions: method

and finally, in your didEnterForeground method, add

if(![[[NSUserDefaults standardUserDefault] objectForKey:@"Your key"] isEqualToString:type]){
  //Reload your main view controller
  [self.window.rootViewController viewDidLoad]; 
  [self.window.rootViewController viewWillAppear:YES];
} 



回答2:


There appears to be a bug in iOS 8 and up where Radio Button settings always revert to the default value in the settings app. Others are running into the same issue: iOS settings bundle PSRadioGroupSpecifier does not show selected value



来源:https://stackoverflow.com/questions/30324452/ios-8-2-and-above-settings-bundle-is-not-showing-selected-item-but-default

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!