From 8227d1cefb20e357250a4a7fe8da32141b6cfc1e Mon Sep 17 00:00:00 2001
From: chenqiyang <1406175257@qq.com>
Date: 星期二, 24 八月 2021 17:29:10 +0800
Subject: [PATCH] 提交原生sdk工程

---
 HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinphoneIntercomVC.m        |   25 ++
 HDLLinPhoneSDK/HDLLinPhoneSDK/HDLCoreManagerDelegate.swift   |   24 ++-
 HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinPhoneSDK.h               |   16 ++
 HDLLinPhoneSDK/HDLLinPhoneSDK/HDLProviderDelegate.swift      |   12 
 HDLLinPhoneSDK/HDLLinPhoneSDK/HDLCallManager.swift           |    9 
 HDLLinPhoneSDK/HDLLinPhoneSDK/HDLCoreManager.swift           |   16 ++
 HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLPOnMonitorViewController.m |   14 +
 HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinphoneManager.m           |  237 +++++++++++++++++++++++++++++
 HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLPOnMonitorViewController.h |    2 
 HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinPhoneSDK.m               |   56 ++++++
 HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinphoneManager.h           |   16 +
 11 files changed, 400 insertions(+), 27 deletions(-)

diff --git a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLCallManager.swift b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLCallManager.swift
index 9f7643b..e4d401d 100644
--- a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLCallManager.swift
+++ b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLCallManager.swift
@@ -176,9 +176,9 @@
         providerDelegate.callInfos.updateValue(callInfo, forKey: uuid)
         providerDelegate.uuids.updateValue(uuid, forKey: callId)
         let state: UIApplication.State = UIApplication.shared.applicationState
-        if state == .background{
-            providerDelegate.reportIncomingCall(call:call, uuid: uuid, handle: handle, hasVideo: hasVideo)
-        }
+//        if state == .background{
+//            providerDelegate.reportIncomingCall(call:call, uuid: uuid, handle: handle, hasVideo: hasVideo)
+//        }
 //        providerDelegate.reportIncomingCall(call:call, uuid: uuid, handle: handle, hasVideo: hasVideo)
     }
     
@@ -202,6 +202,7 @@
         }
         let call = Call.getSwiftObject(cObject: call!)
         acceptCall(call: call, hasVideo: hasVideo)
+//        HDLCallManager.instance().lc?.activateAudioSession(actived: true)
     }
     
     
@@ -337,7 +338,7 @@
     }
 
     // To be removed.
-    static func configAudioSession(audioSession: AVAudioSession) {
+    @objc static func configAudioSession(audioSession: AVAudioSession) {
         do {
             try audioSession.setCategory(AVAudioSession.Category.playAndRecord, mode: AVAudioSession.Mode.voiceChat, options: AVAudioSession.CategoryOptions(rawValue: AVAudioSession.CategoryOptions.allowBluetooth.rawValue | AVAudioSession.CategoryOptions.allowBluetoothA2DP.rawValue))
             try audioSession.setMode(AVAudioSession.Mode.voiceChat)
diff --git a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLCoreManager.swift b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLCoreManager.swift
index ff6c5fb..2672624 100644
--- a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLCoreManager.swift
+++ b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLCoreManager.swift
@@ -25,7 +25,17 @@
     }
 
     @objc private func iterate() {
+
+//        var coreIterateTaskId:UIBackgroundTaskIdentifier = UIBackgroundTaskIdentifier(rawValue: 0)
+//        coreIterateTaskId=UIApplication.shared.beginBackgroundTask(expirationHandler: {
+//            UIApplication.shared.endBackgroundTask(coreIterateTaskId)
+//        })
+        
         lc?.iterate()
+        
+//        if coreIterateTaskId != UIBackgroundTaskIdentifier.invalid {
+//            UIApplication.shared.endBackgroundTask(coreIterateTaskId)
+//        }
     }
 
     @objc func startIterateTimer() {
@@ -50,4 +60,10 @@
             lc?.stop()
         }
     }
+//    
+//    @objc func removeConfig(config:ProxyConfig) {
+//        if (lc != nil) {
+//            lc?.removeProxyConfig(config: config)
+//        }
+//    }
 }
diff --git a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLCoreManagerDelegate.swift b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLCoreManagerDelegate.swift
index 4c3de72..12da730 100644
--- a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLCoreManagerDelegate.swift
+++ b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLCoreManagerDelegate.swift
@@ -31,7 +31,7 @@
             HDLCallManager.setAppData(sCall: call, appData: appData)
         }
         HDLLinPhoneSDK.instance().isIncomingReceivedCallState=false
-
+        print("cstate: \(cstate)")
         switch cstate {
             case .IncomingReceived:
                 print("鎺ユ敹鍒伴�氱煡")
@@ -53,16 +53,18 @@
                         }
                     } else {
                         let state: UIApplication.State = UIApplication.shared.applicationState
-                        HDLCallManager.instance().displayIncomingCall(call: call, handle: address, hasVideo: video, callId: callId!)
-                        if state == .background{
-//                            HDLCallManager.instance().displayIncomingCall(call: call, handle: address, hasVideo: video, callId: callId!)
-                        }else{
-                            
+                        HDLCallManager.instance().displayIncomingCall(call: call, handle: address, hasVideo: true, callId: callId!)
+                        print("鎺ユ敹鍒伴�氱煡2")
+//                        if state == .background{
+//                            print("鎺ユ敹鍒伴�氱煡3")
+////                            HDLCallManager.instance().displayIncomingCall(call: call, handle: address, hasVideo: video, callId: callId!)
+//                        }else{
 //                             HDLCallManager.instance().acceptCall(call: call, hasVideo: call.params?.videoEnabled ?? false)
-                            let dict: Dictionary<String, Any> = ["state":10,"cfg":"","message":"","callID":call.callLog?.callId ?? "","hasVideo":call.params?.videoEnabled ?? false]
+                            print("鎺ユ敹鍒伴�氱煡4")
+                            let dict: Dictionary<String, Any> = ["state":10,"cfg":"","message":"","callID":call.callLog?.callId ?? "","hasVideo":call.params?.videoEnabled ?? false,"userName":call.remoteAddress?.username ?? ""]
                             NotificationCenter.default.post(name: NSNotification.Name(rawValue: "LinphoneRegistrationUpdate"), object: nil, userInfo: dict)
                             HDLLinPhoneSDK.instance().isIncomingReceivedCallState=true
-                        }
+//                        }
                     }
                 }
                 break
@@ -159,11 +161,17 @@
                         HDLCallManager.instance().requestTransaction(transaction, action: "endCall")
                     }
                 }
+                let dict: Dictionary<String, Any> = ["state":11,"cfg":"","message":"","callID":call.callLog?.callId ?? "","hasVideo":call.params?.videoEnabled ?? false,"userName":call.remoteAddress?.username ?? ""]
+                NotificationCenter.default.post(name: NSNotification.Name(rawValue: "LinphoneRegistrationUpdate"), object: nil, userInfo: dict)
                 break
             case .Released:
                 call.userData = nil
+                print("release 浜�")
+                let dict: Dictionary<String, Any> = ["state":12,"cfg":"","message":"","callID":call.callLog?.callId ?? "","hasVideo":call.params?.videoEnabled ?? false,"userName":call.remoteAddress?.username ?? ""]
+                NotificationCenter.default.post(name: NSNotification.Name(rawValue: "LinphoneRegistrationUpdate"), object: nil, userInfo: dict)
                 break
             case .Referred:
+                print("Referred 浜�")
                 HDLCallManager.instance().referedFromCall = call.callLog?.callId
                 break
             default:
diff --git a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLPOnMonitorViewController.h b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLPOnMonitorViewController.h
index 659757c..f36cb05 100644
--- a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLPOnMonitorViewController.h
+++ b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLPOnMonitorViewController.h
@@ -19,6 +19,8 @@
 @property (strong, nonatomic) NSString *userName;//鍛煎彨璐﹀彿
 @property (strong, nonatomic) NSString *titleName;//鏍囬
 
+-(void)showUIAlertViewWithBack:(NSString *)mes;
+
 
 #pragma mark 瀵瑰鎺ュ彛鏂规硶
 
diff --git a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLPOnMonitorViewController.m b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLPOnMonitorViewController.m
index f11f591..cdf8a18 100644
--- a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLPOnMonitorViewController.m
+++ b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLPOnMonitorViewController.m
@@ -85,9 +85,21 @@
     if (self.titleName&&self.titleName.length!=0) {
         self.titleUILabel.text=self.titleName;
     }
+    
+    [NSNotificationCenter.defaultCenter addObserver:self
+                                           selector:@selector(registrationUpdate:)
+                                               name:@"LinphoneRegistrationUpdate"
+                                             object:nil];
 }
 
-
+- (void)registrationUpdate:(NSNotification *)notif {
+    int state = [[notif.userInfo objectForKey:@"state"] intValue];
+    if(state==11){//鎸傛柇浜�
+        NSLog(@"鎸傛柇鎴栧嚭閿欎簡");
+        [self showUIAlertViewWithBack:@"鐩戣缁撴潫"];
+        
+    }
+}
 
 -(void)initLlanguage{
     NSString *languageName = [[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] objectAtIndex:0];
diff --git a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinPhoneSDK.h b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinPhoneSDK.h
index 3fedbee..5d38d76 100644
--- a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinPhoneSDK.h
+++ b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinPhoneSDK.h
@@ -69,5 +69,21 @@
 */
 -(void)clearAllConfigs;
 
+/**
+*app杩涘叆鍚庡彴
+*
+*/
+-(void)enterBackground;
 
+/**
+*app鍞ら啋
+*
+*/
+-(void)becomactive;
+
+/**
+*绋嬪簭鏆傝
+*
+*/
+-(void)willResignActive;
 @end
diff --git a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinPhoneSDK.m b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinPhoneSDK.m
index fd8e33c..acb16e1 100644
--- a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinPhoneSDK.m
+++ b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinPhoneSDK.m
@@ -11,6 +11,12 @@
 #import "HDLLinphoneIntercomVC.h"
 #import "HDLLinPhoneCommon.h"
 #import "HDLLPOnMonitorViewController.h"
+
+@interface HDLLinPhoneSDK()
+//@property (nonatomic, strong) HDLLinphoneIntercomVC *IntercomVC;
+//@property (nonatomic, strong) HDLLPOnMonitorViewController *CallVC;
+@end
+
 @implementation HDLLinPhoneSDK
 
 + (instancetype)instance{
@@ -23,6 +29,8 @@
                                                 selector:@selector(registrationUpdate:)
                                                     name:@"LinphoneRegistrationUpdate"
                                                   object:nil];
+//         service.CallVC=nil;
+//         service.IntercomVC=nil;
          
      });
      return service;
@@ -39,7 +47,9 @@
 - (void)registrationUpdate:(NSNotification *)notif {
     LinphoneRegistrationState state = [[notif.userInfo objectForKey:@"state"] intValue];
     if (state == LinphoneRegistrationFailed){
-        
+        NSLog(@"鐧诲け璐�");
+    }else if (state == LinphoneRegistrationCleared){
+        NSLog(@"鐧诲綍娓呯┖");
     } else if (state == LinphoneRegistrationOk) {
         
 //        HDLLinphoneIntercomVC *vc=[[HDLLinphoneIntercomVC alloc]init];
@@ -48,7 +58,10 @@
 //        }];
         NSLog(@"鐧诲綍鎴愬姛鍟�");
     }else if (state==10){//鎺ユ敹鍒板懠鍙�氱煡
-        self.IsAutoJumpCallView=YES;
+//        self.IsAutoJumpCallView=YES;
+        NSString *userName=[NSString stringWithFormat:@"%@",[notif.userInfo objectForKey:@"userName"]];
+        [self.hdlLinphoneCallDelegate onIncomingCall:userName];
+        
         if(self.IsAutoJumpCallView){
                     NSString *callId=[NSString stringWithFormat:@"%@",[notif.userInfo objectForKey:@"callID"]];
                     BOOL hasVideo=(BOOL)[notif.userInfo objectForKey:@"hasVideo"];
@@ -57,12 +70,35 @@
                     vc.CallId=callId;
                     vc.hasVideo=hasVideo;
                     vc.hdlLinphoneCallDelegate=self.hdlLinphoneCallDelegate;
+                    vc.modalPresentationStyle = UIModalPresentationFullScreen;
+//                    self.IntercomVC=vc;
                     [[HDLLinPhoneCommon topMostController] presentViewController:vc animated:YES completion:^{
             
                     }];
         }
 
         
+    }else if(state==11){//鎸傛柇浜�
+//        NSLog(@"鎸傛柇鎴栧嚭閿欎簡");
+//        if (self.IntercomVC) {
+//            __weak typeof(self) weakSelf = self;
+//            [self.IntercomVC dismissViewControllerAnimated:YES completion:^{
+//                weakSelf.IntercomVC=nil;
+//            }];
+//        }
+//
+//        if (self.CallVC) {
+//            __weak typeof(self) weakSelf = self;
+//            [self.CallVC dismissViewControllerAnimated:YES completion:^{
+//                weakSelf.CallVC=nil;
+//            }];
+//        }
+        
+    }else if(state==12){//鍗犵嚎浜�
+//        NSLog(@"鍗犵嚎浜�");
+//        if (self.CallVC) {
+//            [self.CallVC showUIAlertViewWithBack:@"鐩戣缁撴潫"];
+//        }
     }
 }
 
@@ -79,6 +115,7 @@
     vc.modalPresentationStyle = UIModalPresentationFullScreen;
     vc.userName=username;
     vc.titleName=title;
+//    self.CallVC=vc;
     [[HDLLinPhoneCommon topMostController] presentViewController:vc animated:YES completion:^{
         
     }];
@@ -100,16 +137,29 @@
     vc.hdlLinphoneCallDelegate=self.hdlLinphoneCallDelegate;
     vc.titleName=titleName;
     vc.modalPresentationStyle = UIModalPresentationFullScreen;
+//    self.IntercomVC=vc;
     [[HDLLinPhoneCommon topMostController] presentViewController:vc animated:YES completion:^{
         
     }];
 }
 
 -(void)logoutAllLinphoneUser{
-    
+    [HDLLinphoneManager.instance removeAllAccounts];
 }
 
 -(void)clearAllConfigs{
     
 }
+
+-(void)enterBackground{
+    [HDLLinphoneManager.instance enterBackgroundMode];
+}
+
+-(void)becomactive{
+    [HDLLinphoneManager.instance becomeActive];
+}
+
+-(void)willResignActive{
+    [HDLLinphoneManager.instance willResignActive];
+}
 @end
diff --git a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinphoneIntercomVC.m b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinphoneIntercomVC.m
index 136009d..a2556a8 100644
--- a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinphoneIntercomVC.m
+++ b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinphoneIntercomVC.m
@@ -77,8 +77,22 @@
         self.titleUILabel.text=self.titleName;
     }
 //    self.titleUILabel.text=self.titleName;
+    
+    [NSNotificationCenter.defaultCenter addObserver:self
+                                           selector:@selector(registrationUpdate:)
+                                               name:@"LinphoneRegistrationUpdate"
+                                             object:nil];
+
 }
 
+- (void)registrationUpdate:(NSNotification *)notif {
+    int state = [[notif.userInfo objectForKey:@"state"] intValue];
+    if(state==11){//鎸傛柇浜�
+        NSLog(@"鎸傛柇鎴栧嚭閿欎簡");
+        [self showUIAlertViewWithBack:@"閫氳瘽缁撴潫"];
+        
+    }
+}
 
 -(void)initLlanguage{
     NSString *languageName = [[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] objectAtIndex:0];
@@ -629,6 +643,7 @@
 }
 
 -(void)viewWillDisappear:(BOOL)animated{
+    NSLog(@"viewWillDisappear");
     [super viewWillDisappear:animated];
     [self stopPlaySystemSound];
     //闃叉鐢ㄦ埛涓嶆寜鎸傛柇锛屾垨鑰呬笉绛夋敹鍒板鏂圭殑鎸傛柇锛岀偣鍑昏繑鍥炴寜閽��
@@ -646,6 +661,8 @@
         _countdownTimer = nil; // OK
         
     }
+    
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
     
 }
 
@@ -711,7 +728,7 @@
 #pragma 闇囧姩瀹炵幇璨屼技鍜孲DK鍐茬獊 涓嶈兘瀹炵幇闇囧姩
 //寮�濮嬫挱鏀剧殑鏃跺�欒皟鐢�
 -(void)startPlaySystemSound{
-    return;
+//    return;
     //    //闇囧姩鐨勬彁绀烘枃浠跺悕鏀惧埌璧勬簮鐩綍涓�
     //    NSString *path = [[NSBundle mainBundle] pathForResource:@"ring" ofType:@"wav"];
     //    AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &sound);
@@ -724,13 +741,13 @@
 
 //鎵嬪姩鍋滄鎾斁鐨勬椂鍊欒皟鐢�
 - (void)stopPlaySystemSound{
-    return;
+//    return;
     NSLog(@"stop PlaySystemSound");
-    stopRingAndVibration();
+    HDLLPStopRingAndVibration();
 }
 
 //鍋滄鍝嶉搩鍜岄渿鍔紝绉婚櫎鍥炶皟骞跺鐞嗘帀閾冨0鍜岄渿鍔�
-void stopRingAndVibration() {
+void HDLLPStopRingAndVibration() {
     AudioServicesRemoveSystemSoundCompletion(kSystemSoundID_Vibrate);
     //    AudioServicesRemoveSystemSoundCompletion(sound);
     AudioServicesDisposeSystemSoundID(kSystemSoundID_Vibrate);
diff --git a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinphoneManager.h b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinphoneManager.h
index b4e7cd5..4548bf3 100644
--- a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinphoneManager.h
+++ b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinphoneManager.h
@@ -30,7 +30,15 @@
     SystemSoundID vibrate;
 } LinphoneManagerSounds;
 
-@interface HDLLinphoneManager : NSObject
+typedef struct _CallContext {
+    LinphoneCall* call;
+    bool_t cameraIsEnabled;
+} CallContext;
+
+@interface HDLLinphoneManager : NSObject{
+@public
+    CallContext currentCallContextBeforeGoingBackground;
+}
 - (void)launchLinphoneCore;
 + (HDLLinphoneManager*)instance;
 + (NSString*)bundleFile:(NSString*)file;
@@ -45,7 +53,11 @@
 -(void)initalLinPhonal;
 -(void)snapShot;//瑙嗛鎴浘
 -(void)snapShotWithView:(UIView *)view;//瑙嗛鎴浘
-
+-(void)removeAllAccounts;//娉ㄩ攢鐧诲綍
+-(void)clearConfigs;//娓呴櫎閰嶇疆琛�
+- (BOOL)enterBackgroundMode;
+-(void)willResignActive;
+- (void)becomeActive ;
 @property (readonly) const char*  frontCamId;
 @property (readonly) const char*  backCamId;
 @property (readonly) LinphoneManagerSounds sounds;
diff --git a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinphoneManager.m b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinphoneManager.m
index dc8ba1b..29fdda0 100644
--- a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinphoneManager.m
+++ b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLLinphoneManager.m
@@ -34,6 +34,9 @@
 
 @interface HDLLinphoneManager (){
     LinphoneAccountCreator *account_creator;
+    UIBackgroundTaskIdentifier pausedCallBgTask;
+    UIBackgroundTaskIdentifier incallBgTask;
+    NSDate *mLastKeepAliveDate;
 
 }
 @property(strong, nonatomic) AVAudioPlayer* messagePlayer;
@@ -431,6 +434,7 @@
      * grab, if any */
     //    [self iterate];
     // start scheduler
+
     [HDLCoreManager.instance startIterateTimer];
 }
 
@@ -794,6 +798,7 @@
             // reload address book to prepend proxy config domain to contacts' phone number
             // todo: STOP doing that!
             //            [[LinphoneManager.instance fastAddressBook] fetchContactsInBackGroundThread];
+            
             NSLog(@"鐧诲綍鎴愬姛");
         }
     }
@@ -825,6 +830,7 @@
     [HDLCallManager.instance terminateCallWithCall:call];
 }
 -(void)acceptCall{
+//    [HDLCallManager configAudioSessionWithAudioSession:[AVAudioSession sharedInstance]];
     LinphoneCall * call = linphone_core_get_current_call(theLinphoneCore);
     [HDLCallManager.instance acceptCallWithCall:call hasVideo:YES];
 }
@@ -1010,6 +1016,51 @@
     UIImage *image= [HDLLinPhoneCommon captureImageFromView:view];
     [HDLLinPhoneCommon saveImageToPhotosAlbum:image];
 }
+
+
+-(void)removeAllAccounts{
+    
+    const bctbx_list_t *accounts = linphone_core_get_proxy_config_list(theLinphoneCore);
+    size_t count = bctbx_list_size(accounts);
+    for (size_t i = 1; i <= count; i++, accounts = accounts->next) {
+        LinphoneProxyConfig *config = (LinphoneProxyConfig *)accounts->data;
+        if (config!=NULL) {
+            //绉婚櫎config
+            linphone_core_remove_proxy_config(theLinphoneCore, config);
+            const LinphoneAuthInfo *ai = linphone_proxy_config_find_auth_info(config);
+            if (ai) {
+                    linphone_core_remove_auth_info(theLinphoneCore, ai);
+            }
+        
+        }
+
+    }
+        
+}
+
+-(void)clearConfigs{
+//    const bctbx_list_t *proxies=
+//    linphone_core_get_proxy_config_list(theLinphoneCore);
+//    if (proxies==NULL) {
+//        return;
+//    }
+////    NSLog(@"list:%@",list);
+//    while (proxies) {
+//        LinphoneProxyConfig *config = proxies->data;
+//        if (config!=NULL) {
+//            const LinphoneAuthInfo *ai = linphone_proxy_config_find_auth_info(config);
+//            if (ai) {
+//                linphone_core_remove_auth_info(theLinphoneCore, ai);
+//            }
+//            //绉婚櫎config
+//            linphone_core_remove_proxy_config(theLinphoneCore, config);
+//        }
+//
+//
+//        proxies= proxies->next;
+//    }
+}
+
 // C Function
 static void linphone_iphone_registration_state(LinphoneCore *lc, LinphoneProxyConfig *cfg,
                                                LinphoneRegistrationState state, const char *message) {
@@ -1089,6 +1140,192 @@
     }
 }
 
+- (BOOL)enterBackgroundMode {
+    linphone_core_enter_background(theLinphoneCore);
 
+//    LinphoneProxyConfig *proxyCfg = linphone_core_get_default_proxy_config(theLinphoneCore);
+//    BOOL shouldEnterBgMode = FALSE;
+//
+//    // disable presence
+//    [self enableProxyPublish:NO];
+//
+//    // handle proxy config if any
+//    if (proxyCfg) {
+//        const char *refkey = proxyCfg ? linphone_proxy_config_get_ref_key(proxyCfg) : NULL;
+//        BOOL pushNotifEnabled = (refkey && strcmp(refkey, "push_notification") == 0);
+//        if ([HDLConfigManager.instance lpConfigBoolForKeyWithKey:@"backgroundmode_preference"] || pushNotifEnabled) {
+//            if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) {
+//                // For registration register
+//                [self refreshRegisters];
+//            }
+//        }
+//
+//        if ([HDLConfigManager.instance lpConfigBoolForKeyWithKey:@"voip_mode_preference"] && [HDLConfigManager.instance lpConfigBoolForKeyWithKey:@"backgroundmode_preference"] && !pushNotifEnabled) {
+//            // Keep this!! Socket VoIP is deprecated after 9.0, but sometimes it's the only way to keep the phone background and receive the call. For example, when there is only local area network.
+//            // register keepalive
+//            NSLog(@"keepalive淇濇椿");
+//            if ([[UIApplication sharedApplication]
+//                 setKeepAliveTimeout:600 /*(NSTimeInterval)linphone_proxy_config_get_expires(proxyCfg)*/
+//                 handler:^{
+////                     LOGW(@"keepalive handler");
+//                    self->mLastKeepAliveDate = [NSDate date];
+//                     if (theLinphoneCore == nil) {
+////                         LOGW(@"It seems that Linphone BG mode was deactivated, just skipping");
+//                         return;
+//                     }
+////                     [_iapManager check];
+//                     if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) {
+//                         // For registration register
+//                         [self refreshRegisters];
+//                     }
+//                     linphone_core_iterate(theLinphoneCore);
+//                 }]) {
+//                NSLog(@"keepalive handler succesfully registered");
+//                 } else {
+////                     LOGI(@"keepalive handler cannot be registered");
+//                 }
+//            shouldEnterBgMode = TRUE;
+//        }
+//    }
+//
+//    LinphoneCall *currentCall = linphone_core_get_current_call(theLinphoneCore);
+//    const bctbx_list_t *callList = linphone_core_get_calls(theLinphoneCore);
+//    if (!currentCall // no active call
+//        && callList  // at least one call in a non active state
+//        && bctbx_list_find_custom(callList, (bctbx_compare_func)comp_call_state_paused, NULL)) {
+//        [self startCallPausedLongRunningTask];
+//    }
+//    if (callList) // If at least one call exist, enter normal bg mode
+//        shouldEnterBgMode = TRUE;
+//
+//    // Stop the video preview
+//    if (theLinphoneCore) {
+//        linphone_core_enable_video_preview(theLinphoneCore, FALSE);
+//        [self iterate];
+//    }
+//    linphone_core_stop_dtmf_stream(theLinphoneCore);
+//
+////    LOGI(@"Entering [%s] bg mode", shouldEnterBgMode ? "normal" : "lite");
+//    if (!shouldEnterBgMode && floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) {
+//        const char *refkey = proxyCfg ? linphone_proxy_config_get_ref_key(proxyCfg) : NULL;
+//        BOOL pushNotifEnabled = (refkey && strcmp(refkey, "push_notification") == 0);
+//        if (pushNotifEnabled) {
+////            LOGI(@"Keeping lc core to handle push");
+//            return YES;
+//        }
+//        return NO;
+//    }
+    return YES;
+    
+}
 
+- (void)enableProxyPublish:(BOOL)enabled {
+    if (linphone_core_get_global_state(theLinphoneCore) != LinphoneGlobalOn || !linphone_core_get_default_friend_list(theLinphoneCore)) {
+//        LOGW(@"Not changing presence configuration because linphone core not ready yet");
+        return;
+    }
+
+    if ([HDLConfigManager.instance lpConfigBoolForKeyWithKey:@"publish_presence"]) {
+        // set present to "tv", because "available" does not work yet
+        if (enabled) {
+            linphone_core_set_presence_model(theLinphoneCore, linphone_core_create_presence_model_with_activity(theLinphoneCore, LinphonePresenceActivityTV, NULL));
+        }
+
+        const MSList *proxies = linphone_core_get_proxy_config_list(theLinphoneCore);
+        while (proxies) {
+            LinphoneProxyConfig *cfg = proxies->data;
+            linphone_proxy_config_edit(cfg);
+            linphone_proxy_config_enable_publish(cfg, enabled);
+            linphone_proxy_config_done(cfg);
+            proxies = proxies->next;
+        }
+        // force registration update first, then update friend list subscription
+        [self iterate];
+    }
+
+    linphone_core_enable_friend_list_subscription(theLinphoneCore, enabled && [HDLConfigManager.instance lpConfigBoolForKeyWithKey:@"use_rls_presence"]);
+}
+
+- (void)refreshRegisters {
+    linphone_core_refresh_registers(theLinphoneCore); // just to make sure REGISTRATION is up to date
+}
+
+- (void)startCallPausedLongRunningTask {
+    pausedCallBgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
+//            LOGW(@"Call cannot be paused any more, too late");
+        [[UIApplication sharedApplication] endBackgroundTask:self->pausedCallBgTask];
+        }];
+//    LOGI(@"Long running task started, remaining [%@] because at least one call is paused",
+//         [LinphoneUtils intervalToString:[[UIApplication sharedApplication] backgroundTimeRemaining]]);
+}
+
+-(void)willResignActive{
+    LinphoneCall *call = linphone_core_get_current_call(theLinphoneCore);
+
+    if (!call)
+        return;
+
+    /* save call context */
+    HDLLinphoneManager *instance = HDLLinphoneManager.instance;
+    instance->currentCallContextBeforeGoingBackground.call = call;
+    instance->currentCallContextBeforeGoingBackground.cameraIsEnabled = linphone_call_camera_enabled(call);
+
+    const LinphoneCallParams *params = linphone_call_get_current_params(call);
+    if (linphone_call_params_video_enabled(params))
+        linphone_call_enable_camera(call, false);
+}
+
+- (void)becomeActive {
+    linphone_core_enter_foreground(theLinphoneCore);
+
+    [self checkNewVersion];
+
+    // enable presence
+    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) {
+        [self refreshRegisters];
+    }
+    if (pausedCallBgTask) {
+        [[UIApplication sharedApplication] endBackgroundTask:pausedCallBgTask];
+        pausedCallBgTask = 0;
+    }
+    if (incallBgTask) {
+        [[UIApplication sharedApplication] endBackgroundTask:incallBgTask];
+        incallBgTask = 0;
+    }
+
+    /*IOS specific*/
+    linphone_core_start_dtmf_stream(theLinphoneCore);
+    [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo
+     completionHandler:^(BOOL granted){
+        }];
+
+    /*start the video preview in case we are in the main view*/
+    if (linphone_core_video_display_enabled(theLinphoneCore) && [HDLConfigManager.instance lpConfigBoolForKeyWithKey:@"preview_preference"]) {
+        linphone_core_enable_video_preview(theLinphoneCore, TRUE);
+    }
+    /*check last keepalive handler date*/
+    if (mLastKeepAliveDate != Nil) {
+        NSDate *current = [NSDate date];
+        if ([current timeIntervalSinceDate:mLastKeepAliveDate] > 700) {
+            NSString *datestr = [mLastKeepAliveDate description];
+//            LOGW(@"keepalive handler was called for the last time at %@", datestr);
+        }
+    }
+
+    [self enableProxyPublish:YES];
+}
+
+- (void)checkNewVersion {
+//    if (!CHECK_VERSION_UPDATE)
+//        return;
+//    if (theLinphoneCore == nil)
+//        return;
+//    NSString *curVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
+//    const char *curVersionCString = [curVersion cStringUsingEncoding:NSUTF8StringEncoding];
+//    linphone_core_check_for_update(theLinphoneCore, curVersionCString);
+}
+
+static int comp_call_state_paused(const LinphoneCall *call, const void *param) {
+    return linphone_call_get_state(call) != LinphoneCallPaused;
+}
 @end
diff --git a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLProviderDelegate.swift b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLProviderDelegate.swift
index 2818adf..e51c4e9 100644
--- a/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLProviderDelegate.swift
+++ b/HDLLinPhoneSDK/HDLLinPhoneSDK/HDLProviderDelegate.swift
@@ -75,13 +75,14 @@
 
         let callInfo = callInfos[uuid]
         let callId = callInfo?.callId
-       
+//        HDLCallManager.instance().lc?.activateAudioSession(actived: true)
+
         provider.reportNewIncomingCall(with: uuid, update: update) { error in
             if error == nil {
-                
+
                 HDLCallManager.instance().providerDelegate.endCallNotExist(uuid: uuid, timeout: .now() + 20)
             } else {
-               
+
                 if (call == nil) {
                     callInfo?.declined = true
                     self.callInfos.updateValue(callInfo!, forKey: uuid)
@@ -159,11 +160,12 @@
         if (call == nil || call?.state != Call.State.IncomingReceived) {
             // The application is not yet registered or the call is not yet received, mark the call as accepted. The audio session must be configured here.
             HDLCallManager.configAudioSession(audioSession: AVAudioSession.sharedInstance())
+            print("杩涙潵杩欓噷浜�")
             callInfo?.accepted = true
             callInfos.updateValue(callInfo!, forKey: uuid)
             HDLCallManager.instance().providerDelegate.endCallNotExist(uuid: uuid, timeout: .now() + 10)
         } else {
-//            HDLCallManager.instance().acceptCall(call: call!, hasVideo: call!.params?.videoEnabled ?? false)
+            HDLCallManager.instance().acceptCall(call: call!, hasVideo: call!.params?.videoEnabled ?? false)
         }
         action.fulfill()
     }
@@ -268,7 +270,7 @@
     }
 
     func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
-      
+        print("didActivate");
         HDLCallManager.instance().lc?.activateAudioSession(actived: true)
     }
 

--
Gitblit v1.8.0