Question

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.

Was it helpful?

Solution

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;
    }
} 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top