ios voip
ios 實現(xiàn) voip 功能 使用?PushKit?CallKit
VOIP說是一種網(wǎng)絡(luò)電話服務(wù),其實質(zhì)是一種特殊的長連接,使用它每個網(wǎng)絡(luò)電話類APP不需要自己單獨進行保活維護,在進行通話請求時,只需要發(fā)送一條VOIP推送,VOIP推送會將應(yīng)用程序拉起,之后由應(yīng)用程序處理通訊邏輯。VOIP也是Push的一種,只是其是一種特殊的Push,普通的Push當(dāng)應(yīng)用被殺死后可以收到,但是用戶點擊Push消息前應(yīng)用程序是不會被激活的,VOIP則不然,可以直接激活應(yīng)用。
-(void)testVOIP{//注冊VOIP通知PKPushRegistry *pushRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];pushRegistry.delegate = self;pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP]; } - (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type{NSLog(@"拿到token~~~token~~~%@~~~~~~~%@",credentials.token,credentials.type); }- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type {NSLog(@"收到---voip推送 ----實現(xiàn)客戶端邏輯~~~%@",type);}?
Callket 實現(xiàn)
@property (strong, nonatomic) NSUUID *uuid; //主動發(fā)起CallKit的Action的時候,需要使用 @property (strong, nonatomic) CXProvider *provider; //調(diào)用系統(tǒng)來電UI的主要變量 @property (strong, nonatomic) CXCallController *callController; //代碼調(diào)用CallKit中Action的變量 - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type{self.callController = [[CXCallController alloc] init];self.provider = [[CXProvider alloc] initWithConfiguration:[self providerConfiguration]];[self.provider setDelegate:self queue:nil];//queue為nil即為在主隊列CXTransaction *ction = [[CXTransaction alloc] init];//使用CXProvider觸發(fā)一個來電,其中主要內(nèi)容都包含在CXCallUpdate中CXCallUpdate *callUpdate = [[CXCallUpdate alloc] init];//不設(shè)置CXCallUpdate的remoteHandle的話,在通話記錄中就不能啟動到主程序//這個remoteHandle的話,還是必須要是設(shè)置的一個屬性,幾處地方調(diào)用主程序的時候會用到handle中的value值//PS:這個value值可以設(shè)置成其他的字符串,也可以是幾個字符串拼接的,看需求可以靈活使用,比如聯(lián)系人的IDcallUpdate.remoteHandle = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:@"123456789"];//設(shè)置remoteHandle的hasVideo屬性為YES,即會沉淀為視頻通話的通話記錄,并且點擊通話記錄會觸發(fā)相應(yīng)的視頻通話的方法//不過來電的UI仍然與語音相差不大,只是語音通話的文字提示更改為視頻通話,沒有顯示視頻的畫面callUpdate.hasVideo = NO;//TODO::下面幾個沒有具體研究效果callUpdate.supportsDTMF = NO;callUpdate.supportsHolding = NO;callUpdate.supportsGrouping = NO;callUpdate.supportsUngrouping = NO;//'localizedCallerName'屬性就是現(xiàn)實來電人的描述了,比如昵稱或者ID等callUpdate.localizedCallerName = @"小周周";//這里執(zhí)行AVAudioSession的設(shè)置方法,避免了使用引擎的失敗,不設(shè)置會出現(xiàn)無聲的現(xiàn)象//TODO::這里這個在之前測試的時候的確不寫會有問題,也是查資料查到的,現(xiàn)在不知道什么情況,沒有進行測試 // [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];//調(diào)用系統(tǒng)來電,正常就會調(diào)出系統(tǒng)來電的UI[self.provider reportNewIncomingCallWithUUID:ction.UUID update:callUpdate completion:^(NSError * _Nullable error) {//執(zhí)行完成的block}]; }?
總結(jié)
- 上一篇: 遭遇“烧钱瓶颈” 优酷成本结构堪忧
- 下一篇: type=button 字体大一点_机械