2014-01-23 2 views
0

Я хочу сделать приложение, которое непрерывно записывает голос в фоновом режиме. Приложение, подобное прослушиванию, делает именно это. Но я застрял на перерывах. Приложение не может возобновить запись, когда оно сталкивается с прерываниями.Как работает приложение, подобное прослушиванию?

Я использовал это для уведомления:

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(handleAudioSessionInterruption:) 
              name:AVAudioSessionInterruptionNotification 
              object:nil]; 

и возобновить запись у меня есть:

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

    NSNumber *interruptionType = [[notification userInfo] objectForKey:AVAudioSessionInterruptionTypeKey]; 
    NSNumber *interruptionOption = [[notification userInfo] objectForKey:AVAudioSessionInterruptionOptionKey]; 

    switch (interruptionType.unsignedIntegerValue) { 
     case AVAudioSessionInterruptionTypeBegan:{ 
      // • Audio has stopped, already inactive 
      // • Change state of UI, etc., to reflect non-playing state 
      NSLog(@"Audio has stopped, already inactive"); 

      NSLog(@"is recording: %@",[email protected]"yes":@"no"); 

      [self.recorder pause]; 

      NSLog(@"is recording after pause: %@",[email protected]"yes":@"no"); 

      //[recorder pause]; 

     } break; 
     case AVAudioSessionInterruptionTypeEnded:{ 
      // • Make session active 
      // • Update user interface 
      // • AVAudioSessionInterruptionOptionShouldResume option 




      if (interruptionOption.unsignedIntegerValue == AVAudioSessionInterruptionOptionShouldResume) { 
       // Here you should continue playback. 


       //NSLog(@"completed"); 

       NSLog(@"start recording again %d"); 

       //NSLog(@"completed: %d",[recorder record]); 

       // Set the audio file 



       [self.recorder record]; 


       NSLog(@"is recording after again : %@",[email protected]"yes":@"no"); 




       //[player play]; 
      } 
     } break; 
     default: 
      break; 
    } 
} 

ответ

0

Добавить в PLIST в UIBackgroundModes «аудио» в качестве товара 0. Надеюсь, что это поможет - по крайней мере, это работает для меня при воспроизведении звука.

enter image description here

+0

но он не работает в записи. – user3206985

Смежные вопросы