From 615d1d38dc2cecbe37ae026b001a19c7483827b7 Mon Sep 17 00:00:00 2001 From: Christian Schmidt Date: Fri, 8 Sep 2023 15:52:01 +0200 Subject: [PATCH] Allow calling setup() multiple times --- ios/RNCallKeep/RNCallKeep.m | 39 +++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/ios/RNCallKeep/RNCallKeep.m b/ios/RNCallKeep/RNCallKeep.m index 9569e359..54d69592 100644 --- a/ios/RNCallKeep/RNCallKeep.m +++ b/ios/RNCallKeep/RNCallKeep.m @@ -47,7 +47,7 @@ @implementation RNCallKeep NSMutableArray *_delayedEvents; } -static bool isSetupNatively; +static bool isSetup; static CXProvider* sharedProvider; // should initialise in AppDelegate.m @@ -180,10 +180,19 @@ + (NSDictionary *) getSettings { } + (void)initCallKitProvider { - if (sharedProvider == nil) { - NSDictionary *settings = [self getSettings]; - if (settings != nil) { - sharedProvider = [[CXProvider alloc] initWithConfiguration:[RNCallKeep getProviderConfiguration:settings]]; + NSDictionary *settings = [self getSettings]; + + if (settings != nil) { + CXProviderConfiguration *configuration = [RNCallKeep getProviderConfiguration:settings]; + +#ifdef DEBUG + NSLog(@"[RNCallKeep][initCallKitProvider] configuration = %@", configuration); +#endif + + if (sharedProvider == nil) { + sharedProvider = [[CXProvider alloc] initWithConfiguration:configuration]; + } else { + sharedProvider.configuration = configuration; } } } @@ -195,29 +204,29 @@ + (NSString *) getAudioOutput { + (void)setup:(NSDictionary *)options { RNCallKeep *callKeep = [RNCallKeep allocWithZone: nil]; [callKeep setup:options]; - isSetupNatively = YES; } RCT_EXPORT_METHOD(setup:(NSDictionary *)options) { - if (isSetupNatively) { +#ifdef DEBUG + NSLog(@"[RNCallKeep][setup] options = %@", options); +#endif + [self setSettings: options]; + + [RNCallKeep initCallKitProvider]; + + if (isSetup) { #ifdef DEBUG NSLog(@"[RNCallKeep][setup] already setup"); - RCTLog(@"[RNCallKeep][setup] already setup in native code"); #endif return; } -#ifdef DEBUG - NSLog(@"[RNCallKeep][setup] options = %@", options); -#endif + isSetup = YES; + _version = [[[NSProcessInfo alloc] init] operatingSystemVersion]; self.callKeepCallController = [[CXCallController alloc] init]; - [self setSettings: options]; - - [RNCallKeep initCallKitProvider]; - self.callKeepProvider = sharedProvider; [self.callKeepProvider setDelegate:self queue:nil]; }