2012-10-06 182 views
0

我需要利用耳機按鈕按下我的應用程序以外的多媒體。這是迄今爲止我所擁有的功能,它不起作用。當我按下耳機按鈕,我的應用程序沒有響應,而不是音樂播放...檢測耳機按鈕按

- (BOOL)canBecomeFirstResponder { 

return YES; 
} 

- (void)viewDidAppear:(BOOL)animated { 

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; 
if ([self canBecomeFirstResponder]) { 
    [self becomeFirstResponder]; 
    NSLog(@"became first responder"); 
} 

} 

- (void)remoteControlReceivedWithEvent:(UIEvent *)theEvent 
{ 
if (theEvent.type == UIEventTypeRemoteControl) { 
    switch(theEvent.subtype) { 
     case UIEventSubtypeRemoteControlTogglePlayPause: 
      NSLog(@"Hello"); 

     case UIEventSubtypeRemoteControlPlay: 
      NSLog(@"Hello 2"); 
      break; 
     case UIEventSubtypeRemoteControlPause: 
      NSLog(@"Hello 3"); 
      break; 
     case UIEventSubtypeRemoteControlStop: 
      NSLog(@"Hello 4"); 
      break; 
     default: 
      return; 
    } 
} 
} 

回答