【问题标题】:Once I changed the setting in Settings Bundle, Can my App get the change at the same time?一旦我更改了设置包中的设置,我的应用程序可以同时获得更改吗?
【发布时间】:2012-11-07 05:08:25
【问题描述】:

我知道当我的应用程序进入前台时我可以同​​步 NSUserDefaults。但它不能满足我的要求,我希望一旦我在设置包中更改设置,我的应用程序的音量可以同时改变,即使它是在后台运行的。

【问题讨论】:

    标签: ios background nsuserdefaults synchronized settings-bundle


    【解决方案1】:

    我认为,您不能在应用在后台运行时(甚至手动)更改音量!!。

    但是,您可以使用 NSUserDefaultsDidChangeNotification

    检测应用从后台唤醒时的音量设置变化

    例子:

    -(void)viewDidAppear:(BOOL)animated{
    
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(defaultsSettingsChanged) name:NSUserDefaultsDidChangeNotification object:nil];    
      }
    
    - (void)viewDidDisappear:(BOOL)animated{
    
        [[NSNotificationCenter defaultCenter] removeObserver:self];
    
    }
    
    -(void)defaultsSettingsChanged{
    
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
        if([[defaults stringForKey:@"speech"] isEqualToString:@"0"])
        {
            speech.hidden = YES;
        }
    } 
    

    【讨论】:

      猜你喜欢
      • 2011-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 2013-09-24
      相关资源
      最近更新 更多