How to get an update NSUserDefault on iOS 4?

后端 未结 2 665
别跟我提以往
别跟我提以往 2021-02-15 08:52

I am developing an iPhone application, I encounter a problem on the iOS4 because of multi task.

This application has the default settings defined in a Settings.bundle. I

2条回答
  •  说谎
    说谎 (楼主)
    2021-02-15 09:24

    You need to listen for settings changes. Best way to do it is to set up a listener wherever you need it:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(settingsChanged) name:NSUserDefaultsDidChangeNotification object:nil];
    

    The only thing you need to make sure of is that you don't change any settings in your listener, or you get infinite recursion without a little more logic being added in.

    I'd stay away from synchronizing because in my experience I found I had to run it twice. But that's accidental behavior. A listener will notify you when the new settings have been re-read from the store.

提交回复
热议问题