Skip to content

Commit 16ccd59

Browse files
author
Doug Watkins
committed
Changed to use CallKit instead of deprecated API.
Finished the necessary changes --amend Changed to use CallKit instead of deprecated API. Testing new changes Finished the necessary changes --amend
1 parent 7c47b4d commit 16ccd59

File tree

3 files changed

+28
-46
lines changed

3 files changed

+28
-46
lines changed

iOS/RCTCallDetection/RCTCallDetection.xcodeproj/project.pbxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
developmentRegion = English;
106106
hasScannedForEncodings = 0;
107107
knownRegions = (
108+
English,
108109
en,
109110
);
110111
mainGroup = 21AAD4EC1EF50F19002E2B59;

iOS/RCTCallDetection/RCTCallDetection/CallDetectionManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//
44
//
55
// Created by Pritesh Nandgaonkar on 16/06/17.
6+
// Updated by Doug Watkins for Inside Real Estate on 31/07/19
67
// Copyright © 2017 Facebook. All rights reserved.
78
//
89
//
@@ -18,8 +19,7 @@
1819
#import <React/RCTEventEmitter.h>
1920
#endif
2021
#import <Foundation/Foundation.h>
21-
#import <CoreTelephony/CTCallCenter.h>
22-
#import <CoreTelephony/CTCall.h>
22+
#import <CallKit/CallKit.h>
2323

24-
@interface CallDetectionManager : RCTEventEmitter <RCTBridgeModule>
24+
@interface CallDetectionManager : RCTEventEmitter <RCTBridgeModule, CXCallObserverDelegate>
2525
@end

iOS/RCTCallDetection/RCTCallDetection/CallDetectionManager.m

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,21 @@
33
//
44
//
55
// Created by Pritesh Nandgaonkar on 16/06/17.
6+
// Updated by Doug Watkins for Inside Real Estate on 31/07/19
67
// Copyright © 2017 Facebook. All rights reserved.
78
//
89

910
#import "CallDetectionManager.h"
10-
@import CoreTelephony;
11+
@import CallKit;
1112

1213
typedef void (^CallBack)();
1314
@interface CallDetectionManager()
1415

1516
@property(strong, nonatomic) RCTResponseSenderBlock block;
16-
@property(strong, nonatomic, nonnull) CTCallCenter *callCenter;
17-
18-
@end
17+
@property(strong, nonatomic) CXCallObserver* callObserver;
1918

2019
@implementation CallDetectionManager
2120

22-
- (NSDictionary *)constantsToExport
23-
{
24-
return @{
25-
@"Connected" : @"Connected",
26-
@"Dialing" : @"Dialing",
27-
@"Disconnected": @"Disconnected",
28-
@"Incoming" : @"Incoming"
29-
};
30-
}
31-
3221
- (NSArray<NSString *> *)supportedEvents {
3322
return @[@"PhoneCallStateUpdate"];
3423
}
@@ -40,46 +29,38 @@ + (BOOL)requiresMainQueueSetup {
4029
RCT_EXPORT_MODULE()
4130

4231
RCT_EXPORT_METHOD(addCallBlock:(RCTResponseSenderBlock) block) {
43-
// Setup call tracking
44-
self.block = block;
45-
self.callCenter = [[CTCallCenter alloc] init];
46-
__typeof(self) weakSelf = self;
47-
self.callCenter.callEventHandler = ^(CTCall *call) {
48-
[weakSelf handleCall:call];
49-
};
32+
// Setup call tracking
33+
self.block = block;
34+
self.callObserver = [[CXCallObserver alloc] init];
35+
__typeof(self) weakSelf = self;
36+
[self.callObserver setDelegate:weakSelf queue:nil];
5037
}
5138

5239
RCT_EXPORT_METHOD(startListener) {
5340
// Setup call tracking
54-
self.callCenter = [[CTCallCenter alloc] init];
41+
self.callObserver = [[CXCallObserver alloc] init];
5542
__typeof(self) weakSelf = self;
56-
self.callCenter.callEventHandler = ^(CTCall *call) {
57-
[weakSelf handleCall:call];
58-
};
43+
[self.callObserver setDelegate:weakSelf queue:nil];
5944
}
6045

6146
RCT_EXPORT_METHOD(stopListener) {
6247
// Setup call tracking
63-
self.callCenter = nil;
48+
self.callObserver = nil;
6449
}
6550

66-
- (void)handleCall:(CTCall *)call {
67-
68-
NSDictionary *eventNameMap = @{
69-
CTCallStateConnected : @"Connected",
70-
CTCallStateDialing : @"Dialing",
71-
CTCallStateDisconnected : @"Disconnected",
72-
CTCallStateIncoming : @"Incoming"
73-
};
74-
75-
_callCenter = [[CTCallCenter alloc] init];
76-
77-
[_callCenter setCallEventHandler:^(CTCall *call) {
78-
[self sendEventWithName:@"PhoneCallStateUpdate"
79-
body:[eventNameMap objectForKey: call.callState]];
80-
}];
81-
[self sendEventWithName:@"PhoneCallStateUpdate"
82-
body:[eventNameMap objectForKey: call.callState]];
51+
- (void)callObserver:(CXCallObserver *)callObserver callChanged:(CXCall *)call {
52+
if (call.hasEnded === true) {
53+
[self sendEventWithName:@"PhoneCallStateUpdate" body:@"Disconnected"];
54+
}
55+
if (call.isOutgoing === true && call.hasConnected === false) {
56+
[self sendEventWithName:@"PhoneCallStateUpdate" body:@"Dialing"];
57+
}
58+
if (call.isOutgoing === false && call.hasConnected === false) {
59+
[self sendEventWithName:@"PhoneCallStateUpdate" body:@"Incoming"];
60+
}
61+
if (call.hasEnded === false && call.hasConnected === true) {
62+
[self sendEventWithName:@"PhoneCallStateUpdate" body:@"Connected"];
63+
}
8364
}
8465

8566
@end

0 commit comments

Comments
 (0)