一丐吓、監(jiān)聽電話
監(jiān)聽電話的撥出與電話的接收压鉴;
[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(respondsToCallUpdate:)
name:kLinphoneCallUpdate
object:nil];
- (void)respondsToCallUpdate:(NSNotification *)notif
{
LinphoneCall *call = [[notif.userInfo objectForKey:@"call"] pointerValue];
LinphoneCallState state = [[notif.userInfo objectForKey:@"state"] intValue];
NSString *message = [notif.userInfo objectForKey:@"message"];
NSLog(@"----------state----------%ld", state);
switch (state) {
case LinphoneCallIncomingReceived:
{
[self displayIncomingCall:call];
// if (!CallManager.callKitEnabled) {
// [self displayIncomingCall:call];
// }
}
break;
case LinphoneCallIncomingEarlyMedia:
{
if (linphone_core_get_calls_nb(LC) > 1 ||
(floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max)) {
[self displayIncomingCall:call];
}
break;
}
case LinphoneCallOutgoingInit:
case LinphoneCallOutgoingEarlyMedia:
case LinphoneCallOutgoingProgress:
case LinphoneCallOutgoingRinging:
{
CallAppData *data = [CallManager getAppDataWithCall:call];
if (!data.isConference) {
// 如果不是會議,則跳轉到播出電話頁面
[self displayOutgointCall:call];
}
break;
}
case LinphoneCallPausedByRemote:
case LinphoneCallConnected:
{
if (![LinphoneManager.instance isCTCallCenterExist]) {
/*only register CT call center CB for connected call*/
[LinphoneManager.instance setupGSMInteraction];
}
break;
}
case LinphoneCallError: {
[self displayCallError:call message:message];
}
case LinphoneCallEarlyUpdatedByRemote:
case LinphoneCallEarlyUpdating:
case LinphoneCallIdle:
break;
case LinphoneCallReleased:
{
self.ingoingInfo = nil;
if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
dispatch_async(dispatch_get_main_queue(), ^{
[self showCallVC];
[CallManager.instance stopLinphoneCore];
// 退回到撥號頁面
});
}
}
break;
case LinphoneCallPaused:
case LinphoneCallPausing:
case LinphoneCallRefered:
break;
case LinphoneCallResuming: {
break;
}
case LinphoneCallStateStreamsRunning: {
[self configureAudioSession];
}
break;
case LinphoneCallUpdating:
break;
}
}
二、撥打電話
LinphoneAddress *addr = [LinphoneUtils normalizeSipOrPhoneAddress:number];
[[LinphoneManager instance] call:addr];
self.callNumber = number;
if (addr) {
linphone_address_destroy(addr);
}
三陪毡、接聽電話
[CallManager.instance acceptCallWithCall:call hasVideo:YES]
這里的
CallManager
是取自官方demo中關于音頻通話部分的代碼;
四桅滋、取消接聽電話
[CallManager.instance terminateCallWithCall:call];