31
31
32
32
@implementation RNCallKeep
33
33
{
34
- NSMutableDictionary *_settings;
35
34
NSOperatingSystemVersion _version;
36
35
BOOL _isStartCallActionEventListenerAdded;
37
36
}
38
37
38
+ static CXProvider * sharedProvider;
39
+
39
40
// should initialise in AppDelegate.m
40
41
RCT_EXPORT_MODULE ()
41
42
@@ -64,6 +65,7 @@ - (void)dealloc
64
65
if (self.callKeepProvider != nil ) {
65
66
[self .callKeepProvider invalidate ];
66
67
}
68
+ sharedProvider = nil ;
67
69
}
68
70
69
71
// Override method of RCTEventEmitter
@@ -83,15 +85,28 @@ - (void)dealloc
83
85
];
84
86
}
85
87
88
+ + (void )initCallKitProvider {
89
+ if (sharedProvider == nil ) {
90
+ NSDictionary *settings = [[NSUserDefaults standardUserDefaults ] dictionaryForKey: @" RNCallKeepSettings" ];
91
+ sharedProvider = [[CXProvider alloc ] initWithConfiguration: [RNCallKeep getProviderConfiguration: settings]];
92
+ }
93
+ }
94
+
86
95
RCT_EXPORT_METHOD (setup:(NSDictionary *)options)
87
96
{
88
97
#ifdef DEBUG
89
98
NSLog (@" [RNCallKeep][setup] options = %@ " , options);
90
99
#endif
91
100
_version = [[[NSProcessInfo alloc ] init ] operatingSystemVersion ];
92
101
self.callKeepCallController = [[CXCallController alloc ] init ];
93
- _settings = [[NSMutableDictionary alloc ] initWithDictionary: options];
94
- self.callKeepProvider = [[CXProvider alloc ] initWithConfiguration: [self getProviderConfiguration ]];
102
+ NSDictionary *settings = [[NSMutableDictionary alloc ] initWithDictionary: options];
103
+ // Store settings in NSUserDefault
104
+ [[NSUserDefaults standardUserDefaults ] setObject: settings forKey: @" RNCallKeepSettings" ];
105
+ [[NSUserDefaults standardUserDefaults ] synchronize ];
106
+
107
+ [RNCallKeep initCallKitProvider ];
108
+
109
+ self.callKeepProvider = sharedProvider;
95
110
[self .callKeepProvider setDelegate: self queue: nil ];
96
111
}
97
112
@@ -128,7 +143,7 @@ - (void)dealloc
128
143
#ifdef DEBUG
129
144
NSLog (@" [RNCallKeep][displayIncomingCall] uuidString = %@ " , uuidString);
130
145
#endif
131
- int _handleType = [self getHandleType: handleType];
146
+ int _handleType = [RNCallKeep getHandleType: handleType];
132
147
NSUUID *uuid = [[NSUUID alloc ] initWithUUIDString: uuidString];
133
148
CXCallUpdate *callUpdate = [[CXCallUpdate alloc ] init ];
134
149
callUpdate.remoteHandle = [[CXHandle alloc ] initWithType: _handleType value: handle];
@@ -159,7 +174,7 @@ - (void)dealloc
159
174
#ifdef DEBUG
160
175
NSLog (@" [RNCallKeep][startCall] uuidString = %@ " , uuidString);
161
176
#endif
162
- int _handleType = [self getHandleType: handleType];
177
+ int _handleType = [RNCallKeep getHandleType: handleType];
163
178
NSUUID *uuid = [[NSUUID alloc ] initWithUUIDString: uuidString];
164
179
CXHandle *callHandle = [[CXHandle alloc ] initWithType: _handleType value: handle];
165
180
CXStartCallAction *startCallAction = [[CXStartCallAction alloc ] initWithCallUUID: uuid handle: callHandle];
@@ -316,6 +331,32 @@ - (void)requestTransaction:(CXTransaction *)transaction
316
331
}];
317
332
}
318
333
334
+ + (void )reportNewIncomingCall : (NSString *)uuidString
335
+ handle : (NSString *)handle
336
+ handleType : (NSString *)handleType
337
+ hasVideo : (BOOL )hasVideo
338
+ localizedCallerName : (NSString * _Nullable)localizedCallerName
339
+ {
340
+ #ifdef DEBUG
341
+ NSLog (@" [RNCallKeep][reportNewIncomingCall] uuidString = %@ " , uuidString);
342
+ #endif
343
+ int _handleType = [RNCallKeep getHandleType: handleType];
344
+ NSUUID *uuid = [[NSUUID alloc ] initWithUUIDString: uuidString];
345
+ CXCallUpdate *callUpdate = [[CXCallUpdate alloc ] init ];
346
+ callUpdate.remoteHandle = [[CXHandle alloc ] initWithType: _handleType value: handle];
347
+ callUpdate.supportsDTMF = YES ;
348
+ callUpdate.supportsHolding = YES ;
349
+ callUpdate.supportsGrouping = YES ;
350
+ callUpdate.supportsUngrouping = YES ;
351
+ callUpdate.hasVideo = hasVideo;
352
+ callUpdate.localizedCallerName = localizedCallerName;
353
+
354
+ [RNCallKeep initCallKitProvider ];
355
+ [sharedProvider reportNewIncomingCallWithUUID: uuid update: callUpdate completion: ^(NSError * _Nullable error) {
356
+ if (error == nil ) {}
357
+ }];
358
+ }
359
+
319
360
- (BOOL )lessThanIos10_2
320
361
{
321
362
if (_version.majorVersion < 10 ) {
@@ -327,7 +368,7 @@ - (BOOL)lessThanIos10_2
327
368
}
328
369
}
329
370
330
- - (int )getHandleType : (NSString *)handleType
371
+ + (int )getHandleType : (NSString *)handleType
331
372
{
332
373
int _handleType;
333
374
if ([handleType isEqualToString: @" generic" ]) {
@@ -342,30 +383,30 @@ - (int)getHandleType:(NSString *)handleType
342
383
return _handleType;
343
384
}
344
385
345
- - (CXProviderConfiguration *)getProviderConfiguration
386
+ + (CXProviderConfiguration *)getProviderConfiguration : ( NSDictionary *) settings
346
387
{
347
388
#ifdef DEBUG
348
389
NSLog (@" [RNCallKeep][getProviderConfiguration]" );
349
390
#endif
350
- CXProviderConfiguration *providerConfiguration = [[CXProviderConfiguration alloc ] initWithLocalizedName: _settings [@" appName" ]];
391
+ CXProviderConfiguration *providerConfiguration = [[CXProviderConfiguration alloc ] initWithLocalizedName: settings [@" appName" ]];
351
392
providerConfiguration.supportsVideo = YES ;
352
393
providerConfiguration.maximumCallGroups = 3 ;
353
394
providerConfiguration.maximumCallsPerCallGroup = 1 ;
354
395
providerConfiguration.supportedHandleTypes = [NSSet setWithObjects: [NSNumber numberWithInteger: CXHandleTypePhoneNumber], nil ];
355
- if (_settings [@" supportsVideo" ]) {
356
- providerConfiguration.supportsVideo = _settings [@" supportsVideo" ];
396
+ if (settings [@" supportsVideo" ]) {
397
+ providerConfiguration.supportsVideo = settings [@" supportsVideo" ];
357
398
}
358
- if (_settings [@" maximumCallGroups" ]) {
359
- providerConfiguration.maximumCallGroups = [_settings [@" maximumCallGroups" ] integerValue ];
399
+ if (settings [@" maximumCallGroups" ]) {
400
+ providerConfiguration.maximumCallGroups = [settings [@" maximumCallGroups" ] integerValue ];
360
401
}
361
- if (_settings [@" maximumCallsPerCallGroup" ]) {
362
- providerConfiguration.maximumCallsPerCallGroup = [_settings [@" maximumCallsPerCallGroup" ] integerValue ];
402
+ if (settings [@" maximumCallsPerCallGroup" ]) {
403
+ providerConfiguration.maximumCallsPerCallGroup = [settings [@" maximumCallsPerCallGroup" ] integerValue ];
363
404
}
364
- if (_settings [@" imageName" ]) {
365
- providerConfiguration.iconTemplateImageData = UIImagePNGRepresentation ([UIImage imageNamed: _settings [@" imageName" ]]);
405
+ if (settings [@" imageName" ]) {
406
+ providerConfiguration.iconTemplateImageData = UIImagePNGRepresentation ([UIImage imageNamed: settings [@" imageName" ]]);
366
407
}
367
- if (_settings [@" ringtoneSound" ]) {
368
- providerConfiguration.ringtoneSound = _settings [@" ringtoneSound" ];
408
+ if (settings [@" ringtoneSound" ]) {
409
+ providerConfiguration.ringtoneSound = settings [@" ringtoneSound" ];
369
410
}
370
411
return providerConfiguration;
371
412
}
0 commit comments