CTCallCenter - Call Event Handler - in background state

后端 未结 3 1632
谎友^
谎友^ 2020-12-03 20:10

Regarding the Apple documentation there is no way to handle the phone state while the app is suspended: https://developer.apple.com/documentation/coretelephony/ctcallcenter<

相关标签:
3条回答
  • 2020-12-03 20:31

    All tests that I've done I can't receive any using callEventHandler when the application is in background. But, when the application is in foreground, all nicely work.

    The socket works, because iOS handles it for you app and deliver the packtes accordingly. But for that, you need to create a voip socket and add voip to UIBackgroundModes to your App-Info.plist.

    0 讨论(0)
  • 2020-12-03 20:42

    I know some apps run soundless audio files in the background to prevent from being closed after 10 minutes of inactivity.

    Bluetooth, location, and audio can prevent the app from being completely killed.

    My app is able to detect incoming vs outgoing calls while in background because the app stays alive with location updates. We have used audio/bluetooth in the past.

    Without some method of "keepAlive" the OS will suspend your app until some external stimulus reactivates it (push notification, user launch, etc...)

    0 讨论(0)
  • 2020-12-03 20:44

    You will not be able to monitor phone calls in the background using the callEventHandler...

    However, according to this thread in apple dev forums, you can check the currentCalls periodically in the background to determine if calls are in progress.

    Here is the code you should use (to check every seconds) :

    - (void)viewDidLoad {  
        [super viewDidLoad];
    
        _timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(phoneDetection) userInfo:nil repeats:YES];  
    }  
    
    - (void)phoneDetection {
        _callCenter = [[CTCallCenter alloc] init]; // Here is the important part : instanciating a call center each time you want to check !  
    
        [_callCenter setCallEventHandler:^(CTCall *call) {  
            NSLog(@"Call detected");  
        }];  
    
        NSLog(@"%@", _callCenter.currentCalls);  
    }
    
    0 讨论(0)
提交回复
热议问题