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

Fixed app crash when receiving voip push notification in background #174

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,43 @@ To pass caller's name to CallKit via Voip push notification add custom parameter
</Dial>
```

Your app must initialize PKPushRegistry with PushKit push type VoIP at the launch time. As mentioned in the
[PushKit guidelines](https://developer.apple.com/documentation/pushkit/supporting_pushkit_notifications_in_your_app),
the system can't deliver push notifications to your app until you create a PKPushRegistry object for VoIP push type and set the delegate. If your app delays the initialization of PKPushRegistry, your app may receive outdated
PushKit push notifications, and if your app decides not to report the received outdated push notifications to CallKit, iOS may terminate your app.

We will initialize push kit only if RN code had called TwilioVoice.initWithAccessToken(token) and we've cached device token. You can pass same arguments to initPushKitIfTokenCached as you would pass to configureCallKit

```obj-c
// add import
#import <RNTwilioVoice/RNTwilioVoice.h>

@implementation AppDelegate { // <-- add bracket and next two lines
RCTBridge* bridge;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; // REMOVE RCTBridge*
// ...

// add these two lines
_voice = [bridge moduleForClass:RNTwilioVoice.class];
[_voice initPushKitIfTokenCached:@{ @"appName" : @"YOUR FANCY APP NAME" }];

return YES;
}

// add this method to handle taps in call log
- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void(^)(NSArray<id<UIUserActivityRestoring>> *restorableObjects))restorationHandler {
RNTwilioVoice* _voice = [bridge moduleForClass:RNTwilioVoice.class];
[_voice handleRestoration:userActivity];
return YES;
}
```

#### VoIP Service Certificate

Twilio Programmable Voice for iOS utilizes Apple's VoIP Services and VoIP "Push Notifications" instead of FCM. You will need a VoIP Service Certificate from Apple to receive calls. Follow [the official Twilio instructions](https://github.com/twilio/voice-quickstart-ios#7-create-voip-service-certificate) to complete this step.
Expand Down Expand Up @@ -351,6 +388,12 @@ TwilioVoice.addEventListener('deviceDidReceiveIncoming', function(data) {
// }
})

TwilioVoice.addEventListener('iosCallHistoryTap', function(data) {
// {
// call_to: string, // "+441234567890"
// }
})

// Android Only
TwilioVoice.addEventListener('proximity', function(data) {
// {
Expand Down
2 changes: 1 addition & 1 deletion RNTwilioVoice.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
s.source = { git: 'https://github.com/hoxfon/react-native-twilio-programmable-voice', tag: s.version }

s.dependency 'React-Core'
s.dependency 'TwilioVoice', '~> 5.2.0'
s.dependency 'TwilioVoice', '~> 6.3.0'
s.xcconfig = { 'FRAMEWORK_SEARCH_PATHS' => '${PODS_ROOT}/TwilioVoice/Build/iOS' }
s.frameworks = 'TwilioVoice'
s.preserve_paths = 'LICENSE', 'README.md', 'package.json', 'index.js'
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const _eventHandlers = {
callStateRinging: new Map(),
callInviteCancelled: new Map(),
callRejected: new Map(),
iosCallHistoryTap: new Map(),
}

const Twilio = {
Expand Down
3 changes: 3 additions & 0 deletions ios/RNTwilioVoice/RNTwilioVoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@

@interface RNTwilioVoice : RCTEventEmitter <RCTBridgeModule>

- (void) initPushKitIfTokenCached: (NSDictionary *)callKitParams;
- (BOOL) handleRestoration: (NSUserActivity *)userActivity;

@end
Loading