国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS - 自主實現類似微信語音視頻信息聊天 (idoubs詳細使用方法)1.0

2019-11-09 19:05:38
字體:
來源:轉載
供稿:網友

2017 年 本命年到了 一定要兢兢業業 努力去讓自己變得更好~ 先給大家拜個年啦。 這篇文章早在16年底就已經在pages上碼了一遍 因為總有事情 就一直沒有放上來。

好了 話不多說 今天主要不是講如何配置doubango 之前的文章已經提過 鏈接在這里: iOS - 工程引入doubango (idoubs編譯)

也不是教大家怎么判斷對方來電掛機拒接等操作,之前也寫過了,鏈接在這里: iOS - idoubs 通話判斷對方狀態(在線、拒接、無人接聽、掛斷)

最后,在放上本人自主寫的一個DemoApp , github地址是: ZYDoubs下載地址

隨意展示一下頁面(還在完善中 沒有完全做完 但是可以先關注呀~) 通話界面

================================================================================

注意聽講,下面進入正題

一、引擎:

1、相關類:NgnEngine

2、使用說明:

引擎類具有8個服務,分別為:協議服務、配置服務、聯系人服務、http連接服務、歷史服務、聲音服務、網絡服務、存儲服務。其中最為重要的是協議服務,里面有協議棧,用來回調(內部已處理)。NgnBaseService<INgnSipService>* mSipService;NgnBaseService<INgnConfigurationService>* mConfigurationService;NgnBaseService<INgnContactService>* mContactService;NgnBaseService<INgnHttpClientService>* mHttpClientService;NgnBaseService<INgnHistoryService>* mHistoryService;NgnBaseService<INgnSoundService>* mSoundService;NgnBaseService<INgnNetworkService>* mNetworkService;NgnBaseService<INgnStorageService>* mStorageService;

3、詳細說明:

①獲取引擎: idoubs整體邏輯是只用一個引擎。為了能跑通程序,通常用以下代碼獲取全局引擎。

[NgnEngine sharedInstance]

②打開服務:會把2中的服務打開。

[[NgnEngine sharedInstance] start];

③停止服務:

[[NgnEngine sharedInstance] stop];

④程序處于后臺時,可以使用startKeepAwake方法保持喚醒狀態。

[[NgnEngine sharedInstance] startKeepAwake];

⑤相對應,結束保持喚醒狀態。

[[NgnEngine sharedInstance] stopKeepAwake];

二、配置服務:

1、相關類: NgnConfigurationService

2、使用說明:

設置昵稱:key字段 IDENTITY_DISPLAY_NAME設置impi : key字段 IDENTITY_IMPI設置impu: key字段 IDENTITY_IMPU設置sip密碼:key字段 IDENTITY_PASSWord設置域:key字段 NETWORK_REALM設置代理主機: key字段 NETWORK_PCSCF_HOST設置代理主機端口: key字段 NETWORK_PCSCF_PORT設置是否允許3G網絡: key字段 NETWORK_USE_3G設置是否允許3GPP Early IMS: key字段 NETWORK_USE_EARLY_IMS設置是否允許后臺保持清醒: key字段 NETWORK_USE_KEEPAWAKE

3、具體使用:

UserManager * user = [UserManagerTool userManager]; NSString * kPublicIdentity = [NSString stringWithFormat:@"sip:%@@%@",user.user_sip,user.sip_host_addr]; // set credentials [[NgnEngine sharedInstance].configurationService setStringWithKey:IDENTITY_DISPLAY_NAME andValue:user.worker_name]; [[NgnEngine sharedInstance].configurationService setStringWithKey:IDENTITY_IMPI andValue:user.user_sip]; [[NgnEngine sharedInstance].configurationService setStringWithKey:IDENTITY_IMPU andValue:kPublicIdentity]; [[NgnEngine sharedInstance].configurationService setStringWithKey:IDENTITY_PASSWORD andValue:user.user_password]; [[NgnEngine sharedInstance].configurationService setStringWithKey:NETWORK_REALM andValue:user.sip_host_addr]; [[NgnEngine sharedInstance].configurationService setStringWithKey:NETWORK_PCSCF_HOST andValue:user.sip_host_addr]; int intPort = [user.sip_host_port intValue]; [[NgnEngine sharedInstance].configurationService setIntWithKey:NETWORK_PCSCF_PORT andValue:intPort]; [[NgnEngine sharedInstance].configurationService setBoolWithKey:NETWORK_USE_EARLY_IMS andValue:YES]; [[NgnEngine sharedInstance].configurationService setBoolWithKey:NETWORK_USE_3G andValue:YES]; [[NgnEngine sharedInstance].configurationService setBoolWithKey:NETWORK_USE_KEEPAWAKE andValue:YES]; SYLog(@" 配置 %@ /n%@/n %@/n",user.user_sip,user.user_password,kPublicIdentity);

三、協議服務:

1、相關類: NgnSipService

2、使用說明:

①注冊(可以理解為登錄) 內部實現開啟一個新的協議棧用來回調事件狀態等。 注意:必須先配置好再注冊

[[NgnEngine sharedInstance].sipService registerIdentity];

②注銷: 內部實現 銷毀協議棧,停止服務。

[[NgnEngine sharedInstance].sipService unRegisterIdentity];

③判斷是否注冊: 返回BOOL類型

[[NgnEngine sharedInstance].sipService isRegistered];

四、撥打中轉站

1、相關類:CallViewController

2、CallViewController 相當于一個中轉站,撥打和接收都要通過它

①撥打語音 參數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]; }}

五、語音撥打界面

1、相關類:AudioCallViewController

2、使用:

①注冊通知:用來獲取撥打電話的狀態,通過狀態來判斷“通話中或已掛斷等”

-(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];

六、視頻撥打界面

1、相關類:VideoCallViewController

2、使用方法:

大部分同語言撥打界面,在此不重復敘述!

未完待續,感謝你的耐心! 有疑問可以留言呀,雖然看的人不多 - -, 需要再詳解哪部分留言或私信,我會整合放在下一篇文章里!


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 马尔康县| 尼玛县| 育儿| 江门市| 双鸭山市| 喜德县| 丰台区| 天长市| 稻城县| 江达县| 拜泉县| 泗洪县| 临漳县| 宜君县| 大荔县| 藁城市| 云梦县| 双辽市| 聂拉木县| 余干县| 凤山市| 枞阳县| 洮南市| 济阳县| 霍林郭勒市| 台中县| 姜堰市| 闽侯县| 垫江县| 湘潭县| 宁安市| 怀安县| 金堂县| 翁牛特旗| 清徐县| 新化县| 祁连县| 隆德县| 保山市| 河曲县| 库伦旗|