1

I am creating a app in which when the app is in background and user changes the volume in iPhone app should came to know about it. Any ideas or clues?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{
    //self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    // Override point for customization after application launch.

    AudioSessionInitialize(NULL, NULL, NULL, NULL);

    AudioSessionSetActive(true);

    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(volumeChanged:)
     name:@"AVSystemController_SystemVolumeDidChangeNotification"
     object:nil];

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    LoginVC *login=[[LoginVC alloc]initWithNibName:@"LoginVC" bundle:nil];

    self.navigate=[[UINavigationController alloc]initWithRootViewController:login];

    [self.window addSubview:navigate.view];

    [login release];

    [self.window makeKeyAndVisible];

    return YES;


}

- (void)volumeChanged:(NSNotification *)notification
{

    float volume =
    [[[notification userInfo]
      objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"]
     floatValue];


    NSLog(@"chfi");



  // Do stuff with volume
}

I Have Used This code But its not getting Called.

Michael Celey
  • 12,645
  • 6
  • 57
  • 62
  • Can't do it. Can you explain what you're trying to do more generally? There might be an alternative solution. – woz Jan 28 '13 at 13:03
  • Thanks for reply. I just wanted to detect the hardware volume detection when the app is in background. – user1316176 Jan 28 '13 at 13:06
  • Why do you want to do that? There may be a different way to achieve the same effect. – woz Jan 28 '13 at 13:08
  • I was wrong. It looks like it might be possible. Try this: http://stackoverflow.com/questions/3651252/how-to-get-audio-volume-level-and-volume-changed-notifications-on-ios-4 – woz Jan 28 '13 at 13:09
  • It is a process in the app when the app is in the background and user changes the volume of a Iphone i had to send a message to the server thats why. – user1316176 Jan 28 '13 at 13:10
  • Thanks for the link .I had tried that its not working in IOS 6.0 – user1316176 Jan 28 '13 at 13:11

1 Answers1

0

You can set a listener. When volume changed, the call back method will be getting called.

Justin Mathews
  • 512
  • 4
  • 18