diff --git a/README.md b/README.md index 264d5077..f49ffff8 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,34 @@ const options = { RNCallKeep.setup(options).then(accepted => {}); ``` +iOS only. + +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();`. + +```objective-c +@implementation AppDelegate +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + self.bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; + + [RNCallKeep setup:@{ + @"appName": @"Awesome App", + @"maximumCallGroups": @3, + @"maximumCallsPerCallGroup": @1, + @"supportsVideo": @NO, + }]; + + RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:self.bridge + moduleName:@"App" + initialProperties:nil]; + + // ======== OTHER CODE REDACTED ========== + + return YES; +} + +``` + - `options`: Object - `ios`: object - `appName`: string (required) @@ -93,7 +121,7 @@ RNCallKeep.setup(options).then(accepted => {}); - `additionalPermissions`: [PermissionsAndroid] (optional) Any additional permissions you'd like your app to have at first launch. Can be used to simplify permission flows and avoid multiple popups to the user at different times. - + `setup` calls internally `registerPhoneAccount` and `registerEvents`. ## Constants @@ -641,6 +669,8 @@ Called as soon as JS context initializes if there were some actions performed by 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. +In order for this event to reliably fire, it's necessary to perform setup in `AppDelegate.m` + **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.** ```js diff --git a/ios/RNCallKeep/RNCallKeep.h b/ios/RNCallKeep/RNCallKeep.h index 47ce98b3..c8e7bbdf 100644 --- a/ios/RNCallKeep/RNCallKeep.h +++ b/ios/RNCallKeep/RNCallKeep.h @@ -45,4 +45,6 @@ continueUserActivity:(NSUserActivity *)userActivity + (BOOL)isCallActive:(NSString *)uuidString; ++ (void)setup:(NSDictionary *)options; + @end diff --git a/ios/RNCallKeep/RNCallKeep.m b/ios/RNCallKeep/RNCallKeep.m index 86b64882..b87139b9 100644 --- a/ios/RNCallKeep/RNCallKeep.m +++ b/ios/RNCallKeep/RNCallKeep.m @@ -12,6 +12,7 @@ #import #import #import +#import #import @@ -43,6 +44,7 @@ @implementation RNCallKeep NSMutableArray *_delayedEvents; } +static bool isSetupNatively; static CXProvider* sharedProvider; // should initialise in AppDelegate.m @@ -55,7 +57,7 @@ - (instancetype)init #endif if (self = [super init]) { _isStartCallActionEventListenerAdded = NO; - _delayedEvents = [NSMutableArray array]; + if (_delayedEvents == nil) _delayedEvents = [NSMutableArray array]; } return self; } @@ -118,10 +120,11 @@ - (void)sendEventWithNameWrapper:(NSString *)name body:(id)body { if (_hasListeners) { [self sendEventWithName:name body:body]; } else { - NSDictionary *dictionary = @{ - @"name": name, - @"data": body - }; + NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys: + name, @"name", + body, @"data", + nil + ]; [_delayedEvents addObject:dictionary]; } } @@ -133,8 +136,22 @@ + (void)initCallKitProvider { } } ++ (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] already setup"); + RCTLog(@"[RNCallKeep][setup] already setup in native code"); +#endif + return; + } + #ifdef DEBUG NSLog(@"[RNCallKeep][setup] options = %@", options); #endif @@ -183,7 +200,7 @@ + (void)initCallKitProvider { supportsHolding:(BOOL)supportsHolding supportsDTMF:(BOOL)supportsDTMF supportsGrouping:(BOOL)supportsGrouping - supportsUngrouping:(BOOL)supportsUngrouping) + supportsUngrouping:(BOOL)supportsUngrouping) { [RNCallKeep reportNewIncomingCall: uuidString handle: handle