Skip to content

Commit e5607f5

Browse files
committed
Added documentation and change code so subsequent calls to setup will only be ignored if initial setup was done in AppDelegate.m
1 parent 4690abc commit e5607f5

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,34 @@ const options = {
6161
RNCallKeep.setup(options).then(accepted => {});
6262
```
6363

64+
iOS only.
65+
66+
Alternative on iOS you can perform setup in `AppDelegate.m`. Doing this allows capturing events prior to the react native event bridge being up. Please be aware that calling setup in `AppDelegate.m` will ignore any subsequent calls to `RNCallKeep.setup();`.
67+
68+
```objective-c
69+
@implementation AppDelegate
70+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
71+
{
72+
self.bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
73+
74+
[RNCallKeep setup:@{
75+
@"appName": @"Awesome App",
76+
@"maximumCallGroups": @3,
77+
@"maximumCallsPerCallGroup": @1,
78+
@"supportsVideo": @NO,
79+
}];
80+
81+
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:self.bridge
82+
moduleName:@"App"
83+
initialProperties:nil];
84+
85+
// ======== OTHER CODE REDACTED ==========
86+
87+
return YES;
88+
}
89+
90+
```
91+
6492
- `options`: Object
6593
- `ios`: object
6694
- `appName`: string (required)
@@ -93,7 +121,7 @@ RNCallKeep.setup(options).then(accepted => {});
93121
- `additionalPermissions`: [PermissionsAndroid] (optional)
94122
Any additional permissions you'd like your app to have at first launch. Can be used to simplify permission flows and avoid
95123
multiple popups to the user at different times.
96-
124+
97125
`setup` calls internally `registerPhoneAccount` and `registerEvents`.
98126
99127
## Constants
@@ -641,6 +669,8 @@ Called as soon as JS context initializes if there were some actions performed by
641669

642670
Since iOS 13, you must display incoming call on receiving PushKit push notification. But if app was killed, it takes some time to create JS context. If user answers the call (or ends it) before JS context has been initialized, user actions will be passed as events array of this event. Similar situation can happen if user would like to start a call from Recents or similar iOS app, assuming that your app was in killed state.
643671

672+
In order for this event to reliably fire, it's necessary to perform setup in `AppDelegate.m`
673+
644674
**NOTE: You still need to subscribe / handle the rest events as usuall. This is just a helper whcih cache and propagate early fired events if and only if for "the native events which DID fire BEFORE js bridge is initialed", it does NOT mean this will have events each time when the app reopened.**
645675

646676
```js

ios/RNCallKeep/RNCallKeep.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#import <React/RCTConvert.h>
1313
#import <React/RCTEventDispatcher.h>
1414
#import <React/RCTUtils.h>
15+
#import <React/RCTLog.h>
1516

1617
#import <AVFoundation/AVAudioSession.h>
1718

@@ -41,9 +42,9 @@ @implementation RNCallKeep
4142
BOOL _isStartCallActionEventListenerAdded;
4243
bool _hasListeners;
4344
NSMutableArray *_delayedEvents;
44-
bool _isSetup;
4545
}
4646

47+
static bool isSetupNatively;
4748
static CXProvider* sharedProvider;
4849

4950
// should initialise in AppDelegate.m
@@ -138,13 +139,15 @@ + (void)initCallKitProvider {
138139
+ (void)setup:(NSDictionary *)options {
139140
RNCallKeep *callKeep = [RNCallKeep allocWithZone: nil];
140141
[callKeep setup:options];
142+
isSetupNatively = YES;
141143
}
142144

143145
RCT_EXPORT_METHOD(setup:(NSDictionary *)options)
144146
{
145-
if (_isSetup) {
147+
if (isSetupNatively) {
146148
#ifdef DEBUG
147149
NSLog(@"[RNCallKeep][setup] already setup");
150+
RCTLog(@"[RNCallKeep][setup] already setup in native code");
148151
#endif
149152
return;
150153
}
@@ -163,8 +166,6 @@ + (void)setup:(NSDictionary *)options {
163166

164167
self.callKeepProvider = sharedProvider;
165168
[self.callKeepProvider setDelegate:self queue:nil];
166-
167-
_isSetup = YES;
168169
}
169170

170171
RCT_REMAP_METHOD(checkIfBusy,

0 commit comments

Comments
 (0)