2013-10-10 2 views
2

이 방법을 사용했습니다. How do I get my AVPlayer to play while app is in background? 백그라운드에서 AVPlayer를 재생하여 사파리를 탐색하는 동안 사용자가들을 수 있도록했습니다. 이제는 문제가 발생합니다. 전화가 걸려 올 때 AVPlayer가 계속 재생됩니다. 통화 도중 계속 재생됩니다. AVPlayer를 수동으로 중지하고 시작할 수 있도록 수신 전화 및 종료 통화 ​​이벤트를 잡는 방법이 있습니까?들어오는 호출에 대한 AVPlayer를 수동으로 방해하는 방법

답변

1

coreTelephony 프레임 워크를 통해 수신 전화를 찾거나 탐지해야합니다. 거기에서 귀하의 AVPlayer을 중지하기위한 귀하의 현지 통지를 시작해야합니다. 이

 CTCallCenter * _callCenter = [[CTCallCenter alloc] init]; 
    _callCenter.callEventHandler = ^(CTCall* call) 
    { 

     if ([call.callState isEqualToString:CTCallStateDisconnected]) 
     { 
      NSLog(@"Call has been disconnected"); 
     } 
     else if([call.callState isEqualToString:CTCallStateDialing]) 
     { 
      NSLog(@"Call start"); 
     } 
     else if ([call.callState isEqualToString:CTCallStateConnected]) 
     { 

      NSLog(@"Call has just been connected"); 
     } 
     else if([call.callState isEqualToString:CTCallStateIncoming]) 
     { 
      NSLog(@"Call is incoming"); 
      // You have to initiate/post your local notification through NSNotification center like this 
     [[NSNotificationCenter defaultCenter] postNotificationName:@"stopAVPlayer" object:nil]; 
     } else 
     { 
      NSLog(@"None of the conditions"); 
     } 


    }; 

이를 지칭 가져온 후 수행 https://developer.apple.com/library/ios/navigation/#section=Frameworks&topic=CoreTelephony

+0

예제 코드는 해당 링크에서 누락 된 것 같습니다. AppDelegate에서 CTCallCenter를 작성하고 NSNotificationCenter를 통해 ViewController 메소드와 통신해야합니까? 아니면 View Controller에서 AVPlayer 인스턴스와 함께 생성 될 수 있습니까? – TijuanaKez

관련 문제