Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IOS] Allow calling setup() multiple times #732

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions ios/RNCallKeep/RNCallKeep.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ @implementation RNCallKeep
NSMutableArray *_delayedEvents;
}

static bool isSetupNatively;
static bool isSetup;
static CXProvider* sharedProvider;

// should initialise in AppDelegate.m
Expand Down Expand Up @@ -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;
}
}
}
Expand All @@ -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];
}
Expand Down