2013-10-10 22 views

回答

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