【iPhone开发常用代码积累】在应用程序中添加用户默认设置

    技术2022-06-23  99

    在delegate中

     

    - (void)applicationDidFinishLaunching:(UIApplication *)application { //从用户设置中读取上一次的设置 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; isBlur = [defaults boolForKey:kBlurValue]; openVoice = [defaults boolForKey:kVoiceValue]; level = [defaults objectForKey:kLevelValue]; countTime = [defaults integerForKey:kCountTime]; highFirst = [defaults floatForKey:kHighFirstScore]; midFirst = [defaults floatForKey:kMidFirstScore]; beginFirst = [defaults floatForKey:kBeginFirstScore]; } - (void)applicationWillTerminate:(UIApplication *)application { //保存用户设置 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setBool:isBlur forKey:kBlurValue]; [defaults setBool:openVoice forKey:kVoiceValue]; [defaults setObject:level forKey:kLevelValue]; [defaults setInteger:countTime forKey:kCountTime]; [defaults setFloat:highFirst forKey:kHighFirstScore]; [defaults setFloat:midFirst forKey:kMidFirstScore]; [defaults setFloat:beginFirst forKey:kBeginFirstScore]; }

     

     

    具体见HitBean


    最新回复(0)