464027401@qq.com
2021-12-15 2e150f4bb015d843dae94a9c1281a062fca5162b
HDLLinPhoneSDK£¨OC£©/HDLLinPhoneSDK/HDLLinphoneManager.m
@@ -559,6 +559,8 @@
    linphone_core_set_preferred_video_size([HDLLinphoneManager getLc], vsize);
    linphone_core_set_video_preset([HDLLinphoneManager getLc], [@"custom" UTF8String]);
    linphone_core_set_preferred_framerate([HDLLinphoneManager getLc], 5);
//    linphone_core_enable_video_capture([HDLLinphoneManager getLc], false);
//    linphone_core_enable_video_preview([HDLLinphoneManager getLc], FALSE);
}
@@ -1063,45 +1065,45 @@
            : @"";
         NSUUID *uuid = (NSUUID *)[self.providerDelegate.uuids objectForKey:callId2];
         if (uuid) {
            LinphoneCall *callKit_call = (LinphoneCall *)linphone_core_get_calls(LC)
            LinphoneCall *callK_call = (LinphoneCall *)linphone_core_get_calls(LC)
               ? linphone_core_get_calls(LC)->data
               : NULL;
            const char *callKit_callId = callKit_call
               ? linphone_call_log_get_call_id(linphone_call_get_call_log(callKit_call))
            const char *call_callId = callK_call
               ? linphone_call_log_get_call_id(linphone_call_get_call_log(callK_call))
               : NULL;
            if (callKit_callId && !_conf) {
            if (call_callId && !_conf) {
               // Create a CallKit call because there's not !
               NSString *callKit_callIdNS = [NSString stringWithUTF8String:callKit_callId];
               NSUUID *callKit_uuid = [NSUUID UUID];
               [HDLLinphoneManager.instance.providerDelegate.uuids setObject:callKit_uuid forKey:callKit_callIdNS];
               [HDLLinphoneManager.instance.providerDelegate.calls setObject:callKit_callIdNS forKey:callKit_uuid];
               NSString *callK_callIdNS = [NSString stringWithUTF8String:call_callId];
               NSUUID *callK_uuid = [NSUUID UUID];
               [HDLLinphoneManager.instance.providerDelegate.uuids setObject:callK_uuid forKey:callK_callIdNS];
               [HDLLinphoneManager.instance.providerDelegate.calls setObject:callK_callIdNS forKey:callK_uuid];
//               NSString *address = [FastAddressBook displayNameForAddress:linphone_call_get_remote_address(callKit_call)];
                    NSString *address=@"";
               CXHandle *handle = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:address];
               CXStartCallAction *act = [[CXStartCallAction alloc] initWithCallUUID:callKit_uuid handle:handle];
               CXTransaction *tr = [[CXTransaction alloc] initWithAction:act];
               [HDLLinphoneManager.instance.providerDelegate.controller requestTransaction:tr completion:^(NSError *err){}];
               [HDLLinphoneManager.instance.providerDelegate.provider reportOutgoingCallWithUUID:callKit_uuid startedConnectingAtDate:nil];
               [HDLLinphoneManager.instance.providerDelegate.provider reportOutgoingCallWithUUID:callKit_uuid connectedAtDate:nil];
//                    NSString *address=@"";
//               CXHandle *handle = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:address];
//               CXStartCallAction *act = [[CXStartCallAction alloc] initWithCallUUID:callKit_uuid handle:handle];
//               CXTransaction *tr = [[CXTransaction alloc] initWithAction:act];
//               [HDLLinphoneManager.instance.providerDelegate.controller requestTransaction:tr completion:^(NSError *err){}];
//               [HDLLinphoneManager.instance.providerDelegate.provider reportOutgoingCallWithUUID:callKit_uuid startedConnectingAtDate:nil];
//               [HDLLinphoneManager.instance.providerDelegate.provider reportOutgoingCallWithUUID:callKit_uuid connectedAtDate:nil];
            }
            CXEndCallAction *act = [[CXEndCallAction alloc] initWithCallUUID:uuid];
            CXTransaction *tr = [[CXTransaction alloc] initWithAction:act];
            [HDLLinphoneManager.instance.providerDelegate.controller requestTransaction:tr completion:^(NSError *err){}];
            LOGI(@"CallKit - clearing CK as call ended on uuid %@",uuid);
            [HDLLinphoneManager.instance.providerDelegate.provider reportOutgoingCallWithUUID:uuid connectedAtDate:[NSDate date]];
            [self.providerDelegate.uuids removeObjectForKey:callId2];
            [self.providerDelegate.calls removeObjectForKey:uuid];
            [self.providerDelegate.provider reportCallWithUUID:uuid endedAtDate:[NSDate date] reason:(state == LinphoneCallError ? CXCallEndedReasonFailed : CXCallEndedReasonRemoteEnded)];
//            CXEndCallAction *act = [[CXEndCallAction alloc] initWithCallUUID:uuid];
//            CXTransaction *tr = [[CXTransaction alloc] initWithAction:act];
//            [HDLLinphoneManager.instance.providerDelegate.controller requestTransaction:tr completion:^(NSError *err){}];
//            LOGI(@"CallKit - clearing CK as call ended on uuid %@",uuid);
//            [HDLLinphoneManager.instance.providerDelegate.provider reportOutgoingCallWithUUID:uuid connectedAtDate:[NSDate date]];
//            [self.providerDelegate.uuids removeObjectForKey:callId2];
//            [self.providerDelegate.calls removeObjectForKey:uuid];
//            [self.providerDelegate.provider reportCallWithUUID:uuid endedAtDate:[NSDate date] reason:(state == LinphoneCallError ? CXCallEndedReasonFailed : CXCallEndedReasonRemoteEnded)];
         } else { // Can happen when Call-ID changes (Replaces header)
            if (linphone_core_get_calls_nb(LC) ==0) { // Need to clear all CK calls
               for (NSUUID *myUuid in self.providerDelegate.calls) {
                  [self.providerDelegate.provider reportCallWithUUID:myUuid
                   endedAtDate:NULL
                   reason:(state == LinphoneCallError
                      ? CXCallEndedReasonFailed
                      : CXCallEndedReasonRemoteEnded)];
               }
//               for (NSUUID *myUuid in self.providerDelegate.calls) {
//                  [self.providerDelegate.provider reportCallWithUUID:myUuid
//                   endedAtDate:NULL
//                   reason:(state == LinphoneCallError
//                      ? CXCallEndedReasonFailed
//                      : CXCallEndedReasonRemoteEnded)];
//               }
               [self.providerDelegate.uuids removeAllObjects];
               [self.providerDelegate.calls removeAllObjects];
            }
@@ -2130,11 +2132,21 @@
   linphone_core_cbs_set_version_update_check_result_received(cbs, linphone_iphone_version_update_check_result_received);
   linphone_core_cbs_set_qrcode_found(cbs, linphone_iphone_qr_code_found);
   linphone_core_cbs_set_user_data(cbs, (__bridge void *)(self));
//    NSLog(@"Creating linphonecore1:%@",_configDb);
    lp_config_set_int(_configDb, [@"app" UTF8String], [@"random_port_preference" UTF8String], 1);
   theLinphoneCore = linphone_factory_create_core_with_config_3(factory, _configDb, NULL);
   linphone_core_add_callbacks(theLinphoneCore, cbs);
   linphone_core_start(theLinphoneCore);
    //设置为随机端口
    LinphoneSipTransports transportValue = {-1, -1, -1, -1};
    // will also update the sip_*_port section of the config
    if (linphone_core_set_sip_transports(theLinphoneCore, &transportValue)) {
        LOGE(@"cannot set transport");
    }
    [self removeAllAccounts];
   // Let the core handle cbs
   linphone_core_cbs_unref(cbs);
@@ -2804,29 +2816,30 @@
      return;
   }
   if (linphone_core_get_calls_nb(theLinphoneCore) < 1 &&
       floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max &&
       self.providerDelegate.callKitCalls < 1) {
        NSLog(@"进这里呼叫了");
      self.providerDelegate.callKitCalls++;
      NSUUID *uuid = [NSUUID UUID];
      [HDLLinphoneManager.instance.providerDelegate.uuids setObject:uuid forKey:@""];
      [HDLLinphoneManager.instance.providerDelegate.calls setObject:@"" forKey:uuid];
      HDLLinphoneManager.instance.providerDelegate.pendingAddr = linphone_address_clone(iaddr);
//      NSString *address = [FastAddressBook displayNameForAddress:iaddr];
        NSString *address =@"unknow";
      CXHandle *handle = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:address];
      CXStartCallAction *act = [[CXStartCallAction alloc] initWithCallUUID:uuid handle:handle];
      CXTransaction *tr = [[CXTransaction alloc] initWithAction:act];
      [HDLLinphoneManager.instance.providerDelegate.controller requestTransaction:tr
       completion:^(NSError *err){
            NSLog(@"呼叫error:%@",err);
         }];
   } else {
        NSLog(@"进doCall呼叫了");
      [self doCall:iaddr];
   }
//   if (linphone_core_get_calls_nb(theLinphoneCore) < 1 &&
//       floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max &&
//       self.providerDelegate.callKitCalls < 1) {
//        NSLog(@"进这里呼叫了");
//      self.providerDelegate.callKitCalls++;
//      NSUUID *uuid = [NSUUID UUID];
//      [HDLLinphoneManager.instance.providerDelegate.uuids setObject:uuid forKey:@""];
//      [HDLLinphoneManager.instance.providerDelegate.calls setObject:@"" forKey:uuid];
//      HDLLinphoneManager.instance.providerDelegate.pendingAddr = linphone_address_clone(iaddr);
////      NSString *address = [FastAddressBook displayNameForAddress:iaddr];
//        NSString *address =@"unknow";
//
//      CXHandle *handle = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:address];
//      CXStartCallAction *act = [[CXStartCallAction alloc] initWithCallUUID:uuid handle:handle];
//      CXTransaction *tr = [[CXTransaction alloc] initWithAction:act];
//      [HDLLinphoneManager.instance.providerDelegate.controller requestTransaction:tr
//       completion:^(NSError *err){
//            NSLog(@"呼叫error:%@",err);
//         }];
//   } else {
//        NSLog(@"进doCall呼叫了");
//      [self doCall:iaddr];
//   }
    [self doCall:iaddr];
}
- (BOOL)doCall:(const LinphoneAddress *)iaddr {