NewXcoder
NewXcoder

Reputation: 715

Once I changed the setting in Settings Bundle, Can my App get the change at the same time?

I know I can synchronize NSUserDefaults when my App enter foreground. But it can't meet my requirements, I want once I change setting in the Setting Bundle, my App's volume can change at the same time, even if it's run in background.

Upvotes: 0

Views: 1639

Answers (1)

Shamsudheen TK
Shamsudheen TK

Reputation: 31311

I think, You can't change volume when app run in background(even manually)!!.

However You can detect the volume settings changes when apps wake from background using NSUserDefaultsDidChangeNotification

Example:

-(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;
    }
} 

Upvotes: 2

Related Questions