I changed the CTCallCenter with CXCallObserver in iOS 10.
Here is my code:
#import <CallKit/CXCallObserver.h>
#import <CallKit/CXCall.h>
-(void)viewDidLoad {
CXCallObserver *callObserver = [[CXCallObserver alloc] init];
[callObserver setDelegate:self queue:nil];
... ...
}
- (void)callObserver:(CXCallObserver *)callObserver callChanged:(CXCall *)call {
if (call.hasConnected) {
NSLog(@"********** voice call connected **********/n");
} else if(call.hasEnded) {
NSLog(@"********** voice call disconnected **********/n");
}
}
But I can't get a voice call event and I got a warning like this:
Sending 'HomeViewController *const __strong' to parameter of incompatible type 'id<CXCallObserverDelegate> _Nullable
Please help me.
Don't forget to store strong reference to callObserver
, so it won't be released too early:
@interface YourClass ()<CXCallObserverDelegate>
@property (nonatomic, strong) CXCallObserver *callObserver;
@end
- (void)viewDidLoad {
[super viewDidLoad];
CXCallObserver *callObserver = [[CXCallObserver alloc] init];
[callObserver setDelegate:self queue:nil];
self.callObserver = callObserver;
}
For more information, check this answer.
You missed the CXCallObserverDelegate.
@interface HomeViewController : UIViewController <CXCallObserverDelegate>
@end
Then the warning will disappear and you get a voice call event. I hope this help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With