1

我正在创建一个应用程序,当应用程序处于后台并且用户更改 iPhone 应用程序中的音量时,应该知道它。有什么想法或线索吗?

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

我已经使用了此代码,但它没有被调用。

4

1 回答 1

0

你可以设置一个监听器。当音量改变时,回调方法将被调用。

于 2013-01-28T13:08:35.627 回答