Как исправить иерархию контроллера вида для AVPlayer? - PullRequest
0 голосов
/ 16 января 2019

У меня есть приложение для iOS с одним игроком и логином. Это должно работать так:

  • 1) Запустить приложение
  • 2) логин
  • 3) после входа в систему видео сразу начинает воспроизводиться
  • 4) если вы выходите из видео, он должен спросить, хотите ли вы выйти из системы
  • 5) если нет, следует продолжить воспроизведение потока
  • 6) если да, выйдите из приложения
  • 7) и если пользователь снова входит в систему, не убивая приложение, он должен повторить шаги с 2-7

Однако мой код делает все, кроме последнего шага. Если пользователь выходит из системы и входит - начинает проигрывать стрим но когда вы нажимаете кнопку «Готово» и пытаетесь выйти из видео, это не работает. Видео остается в полноэкранном режиме и выдает следующее предупреждение:

Warning: <AVPlayerViewController: 0x7f9fca08aa00> is trying to exit full screen, but is not in its view's window's view controller hierarchy. This results in undefined behavior. 

Я действительно новичок в xcode ios и ObjectiveC, и мой код выглядит следующим образом

- (void)viewDidLoad {

    NSLog(@"ChannelListingViewController::viewDidLoad(): Called...");
    [super viewDidLoad];

    self.check=1;

    NSLog(@"ChannelListingViewController::viewDidLoad(): Exiting...");
}

-(void) playVideo
{
    self.channelURL = [TulixAppGlobalConfig getUserSubscribedPlanChannels];


    NSURL *url = [[NSURL alloc] initWithString:[self.channelURL[1] getChannelHlsStreamURL]];
    self.player = [AVPlayer playerWithURL:url];

    // create a player view controller
    [self presentViewController:controller animated:YES completion:nil];
    self.controller.player = self.player;
    [self.player play];

}
-(void) viewDidAppear:(BOOL)animated
{

    self.controller = [[AVPlayerViewController alloc] init];

    NSLog(@"ChannelListingViewController::viewDidAppear(): Called...");
    if(self.check==0)
    {
        NSLog(@" 0 checkvalue: %i",check);
        [self showLogoutConfirmationDialog];
    }
    else{
        self.check =0;
        NSLog(@" 1 checkvalue: %i",check);
        [self playVideo];

    }

    [self spawnKeepAliveThread];
    NSLog(@"ChannelListingViewController::viewDidAppear(): Exiting...");
}

-(void) showLogoutConfirmationDialog
{
    void (^ptrFuncCompletionBlock)(void) = ^(void) {     NSLog(@"ChannelListingViewController::showLogoutConfirmationDialog():GENERIC CALL BACK...");
    [self attemptToLogoutUser];
};
NSLog(@"ChannelListingViewController::showLogoutConfirmationDialog(): Called...");

UIAlertAction* alertActionYes = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault
                                                         handler:^(UIAlertAction * action) {
                                                             //Do Some action here
                                                             NSLog(@"ChannelListingViewController::showLogoutConfirmationDialog:: Called for YES...");
                                                             self.check = 1;
                                                             NSLog(@" yes checkvalue: %i",check);
                                                             [self.activeAlterController dismissViewControllerAnimated:NO completion:ptrFuncCompletionBlock];
                                                             [self attemptToLogoutUser];
                                                         }];
UIAlertAction* alertActionNo = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel
                                                          handler:^(UIAlertAction * action) {
                                                              NSLog(@"ChannelListingViewController::showLogoutConfirmationDialog:: Called for NO...");
                                                              [self playVideo];

                                                          }];

NSMutableArray* arrayAlertActions = [NSMutableArray arrayWithObjects:alertActionYes, alertActionNo, nil];
self.activeAlterController = [HelperUtility showMultiButtonDialogHavingTitle:@"Logout" withMessage:@"Are you sure you want to log out?" andAlertActions:arrayAlertActions];

[self presentViewController:self.activeAlterController animated:YES completion:nil];

NSLog(@"ChannelListingViewController::showLogoutConfirmationDialog(): Exit ");

}

Я действительно не понимаю, почему он не работает после выхода из системы и нуждается в помощи.

...