Não é possível receber remoteControlReceivedWithEvent - objetivo c - ios
Ativei com êxito o meu aplicativo para reproduzir áudio e vídeo em segundo plano depois que a tela estiver bloqueada. No entanto, para uma melhor experiência do usuário, quero mostrar os controles de reprodução e pausa da mídia em execução na tela bloqueada. Depois de seguir alguns blogs online, adicionou o seguinte código:
@interface MyControllerClass () <UIGestureRecognizerDelegate, UIApplicationDelegate>
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:avAsset];
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
NSError *activationError = nil;
BOOL success = [[AVAudioSession sharedInstance] setActive: YES error: &activationError];
}
- (void)viewWillDisappear:(BOOL)animated {
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
[super viewWillDisappear:animated];
}
- (BOOL) canBecomeFirstResponder {
return YES;
}
- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {
NSLog(@"received event %@",receivedEvent);
if (receivedEvent.type == UIEventTypeRemoteControl) {
switch (receivedEvent.subtype) {
case UIEventSubtypeRemoteControlTogglePlayPause: {
if ([self isVideoPlaying]) {
[self.avPlayer pause];
} else {
[self.avPlayer play];
}
break;
}
case UIEventSubtypeRemoteControlPlay: {
[self.avPlayer play];
break;
}
case UIEventSubtypeRemoteControlPause: {
[self.avPlayer pause];
break;
}
default:
break;
}
}
}
Adicionados modos de segundo plano no info.plist
Embora eu possa ver a tela de controle, nenhum evento do usuário é recebido pelo meu aplicativo ao clicar nos botões.
Acredito que estou perdendo algo muito óbvio. Qualquer ponteiro seria útil.
EDIT 1: A resposta aceita emiOS - eventos UIEventTypeRemoteControl não recebidos diz queSeu aplicativo deve ser o aplicativo "Em reprodução". Como eu faço isso?