2017 年 本命年到了 一定要兢兢業業 努力去讓自己變得更好~ 先給大家拜個年啦。 這篇文章早在16年底就已經在pages上碼了一遍 因為總有事情 就一直沒有放上來。
好了 話不多說 今天主要不是講如何配置doubango 之前的文章已經提過 鏈接在這里: iOS - 工程引入doubango (idoubs編譯)
也不是教大家怎么判斷對方來電掛機拒接等操作,之前也寫過了,鏈接在這里: iOS - idoubs 通話判斷對方狀態(在線、拒接、無人接聽、掛斷)
最后,在放上本人自主寫的一個DemoApp , github地址是: ZYDoubs下載地址
隨意展示一下頁面(還在完善中 沒有完全做完 但是可以先關注呀~) 
================================================================================
①獲取引擎: idoubs整體邏輯是只用一個引擎。為了能跑通程序,通常用以下代碼獲取全局引擎。
[NgnEngine sharedInstance]②打開服務:會把2中的服務打開。
[[NgnEngine sharedInstance] start];③停止服務:
[[NgnEngine sharedInstance] stop];④程序處于后臺時,可以使用startKeepAwake方法保持喚醒狀態。
[[NgnEngine sharedInstance] startKeepAwake];⑤相對應,結束保持喚醒狀態。
[[NgnEngine sharedInstance] stopKeepAwake];①注冊(可以理解為登錄) 內部實現開啟一個新的協議棧用來回調事件狀態等。 注意:必須先配置好再注冊
[[NgnEngine sharedInstance].sipService registerIdentity];②注銷: 內部實現 銷毀協議棧,停止服務。
[[NgnEngine sharedInstance].sipService unRegisterIdentity];③判斷是否注冊: 返回BOOL類型
[[NgnEngine sharedInstance].sipService isRegistered];①撥打語音 參數1: 對方的sip賬號的impi 參數2:協議棧
NSString * sipNum = [NSString stringWithFormat:@"%@",self.contactModel.user_sip];[CallViewController makeAudioCallWithRemoteParty:sipNum andSipStack:[[NgnEngine sharedInstance].sipService getSipStack]];②撥打視頻 參數1: 對方的sip賬號的impi 參數2:協議棧
NSString * sipNum = [NSString stringWithFormat:@"%@",self.contactModel.user_sip];[CallViewController makeAudioVideoCallWithRemoteParty:sipNum andSipStack: [[NgnEngine sharedInstance].sipService getSipStack]];③語音視頻呼入,一般是由本地通知發起,通知的notification.userInfo 里面會保存類型, 用來區別是語音/視頻來電 還是 信息來了。 語音/視頻 : kNotifKey_IncomingCall 信息:kNotifKey_IncomingMsg
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{ NSLog(@"notification ==== %@",notification); NSString *notifKey = [notification.userInfo objectForKey:kNotifKey]; if([notifKey isEqualToString:kNotifKey_IncomingCall]){ NSNumber* sessionId = [notification.userInfo objectForKey:kNotifIncomingCall_SessionId]; NgnAVSession* session = [NgnAVSession getSessionWithId:[sessionId longValue]]; if(session){ [CallViewController receiveIncomingCall:session]; application.applicationIconBadgeNumber -= notification.applicationIconBadgeNumber; } } else if([notifKey isEqualToString:kNotifKey_IncomingMsg]){ UserManager * user = [UserManagerTool userManager]; NSString * userName = [notification.userInfo objectForKey:@"userName"]; NSString * myClientId = clientID; NSString * showStr = [notification.userInfo objectForKey:@"content"]; myClientId = [NSString stringWithFormat:@"|=|%@|=|",myClientId]; if ([userName isEqualToString:user.user_sip]) { if (![myClientId isEqualToString: showStr]) { //id賬號不同踢下線 [PMSipTools sipUnRegister]; [self alertLoginOtherWhere]; return; } } if (![self.window.rootViewController isKindOfClass:[MyRootViewController class]]) { return; } MyRootViewController * rootVC = (MyRootViewController *)self.window.rootViewController; UINavigationController * nav = rootVC.midViewController; [nav popToRootViewControllerAnimated:NO]; //跳去聊天界面 [[NSNotificationCenter defaultCenter]postNotificationName:@"pushChatVC" object:userName]; }}①注冊通知:用來獲取撥打電話的狀態,通過狀態來判斷“通話中或已掛斷等”
-(void) onInviteEvent:(NSNotification*)notification { NgnInviteEventArgs* eargs = [notification object]; if(!audioSession || audioSession.id != eargs.sessionId){ return; } switch (eargs.eventType) { case INVITE_EVENT_INPROGRESS: case INVITE_EVENT_INCOMING: case INVITE_EVENT_RINGING: case INVITE_EVENT_LOCAL_HOLD_OK: case INVITE_EVENT_REMOTE_HOLD: default: { // updates view and state [self updateViewAndState]; break; } // transilient events case INVITE_EVENT_MEDIA_UPDATING: { self.labelStatus.text = @"語音來電.."; break; } case INVITE_EVENT_MEDIA_UPDATED: { self.labelStatus.text = @"語音結束中.."; break; } case INVITE_EVENT_TERMINATED: case INVITE_EVENT_TERMWAIT: { // updates view and state [self updateViewAndState]; // releases session [NgnAVSession releaseSession: &audioSession]; // starts timer suicide [NSTimer scheduledTimerWithTimeInterval: kCallTimerSuicide target: self selector: @selector(timerSuicideTick:) userInfo: nil repeats: NO]; break; } }}③掛斷 接受 免提 靜音:
//掛斷- (void) buttonHangupClick{ if(audioSession){ [audioSession hangUpCall]; }}//接受 - (void) buttonAcceptClick{ if(audioSession){ [audioSession acceptCall]; }}//免提- (void)handsFreeBtnClick:(UIButton *)sender { [audioSession setSpeakerEnabled:![audioSession isSpeakerEnabled]]; if([[NgnEngine sharedInstance].soundService setSpeakerEnabled:[audioSession isSpeakerEnabled]]){ self.handsFreeBtn.selected = [audioSession isSpeakerEnabled]; }}//靜音- (void)muteBtnClick:(UIButton *)sender { if([audioSession setMute:![audioSession isMuted]]){ self.muteBtn.selected = [audioSession isMuted]; }}④ 播放來電鈴聲: 來電外放:
[[[NgnEngine sharedInstance] getSoundService] playBackRingTone];來電不外放(聽筒內可以聽到)
[[[NgnEngine sharedInstance] getSoundService] playRingTone];停止播放(在設置了來電免打擾的時候使用)
[[[NgnEngine sharedInstance] getSoundService] stopRingTone];[[[NgnEngine sharedInstance] getSoundService] stopRingBackTone];未完待續,感謝你的耐心! 有疑問可以留言呀,雖然看的人不多 - -, 需要再詳解哪部分留言或私信,我會整合放在下一篇文章里!
新聞熱點
疑難解答