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

Showing caller's name in CallKit #170

Merged
merged 3 commits into from
Dec 10, 2020
Merged
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ cd ios/ && pod install

The iOS library works through [CallKit](https://developer.apple.com/reference/callkit) and handling calls is much simpler than the Android implementation as CallKit handles the inbound calls answering, ignoring, or rejecting. Outbound calls must be controlled by custom React-Native screens and controls.

To pass caller's name to CallKit via voip push notification add custom parameter 'CallerName' to Twilio Dial verb.
```xml
<Dial>
<Client>
<Identity>Client</Identity>
<Parameter name="CallerName">NAME TO DISPLAY</Parameter>
</Client>
</Dial>
```

#### 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
8 changes: 7 additions & 1 deletion ios/RNTwilioVoice/RNTwilioVoice.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@import TwilioVoice;

NSString * const kCachedDeviceToken = @"CachedDeviceToken";
NSString * const kCallerNameCustomParameter = @"CallerName";

@interface RNTwilioVoice () <PKPushRegistryDelegate, TVONotificationDelegate, TVOCallDelegate, CXProviderDelegate>

Expand Down Expand Up @@ -347,6 +348,9 @@ - (void)callInviteReceived:(TVOCallInvite *)callInvite {
if (callInvite.from) {
from = [callInvite.from stringByReplacingOccurrencesOfString:@"client:" withString:@""];
}
if (callInvite.customParameters[kCallerNameCustomParameter]) {
from = callInvite.customParameters[kCallerNameCustomParameter];
}
// Always report to CallKit
[self reportIncomingCallFrom:from withUUID:callInvite.uuid];
self.activeCallInvites[[callInvite.uuid UUIDString]] = callInvite;
Expand Down Expand Up @@ -722,7 +726,9 @@ - (void)performStartCallActionWithUUID:(NSUUID *)uuid handle:(NSString *)handle
}

- (void)reportIncomingCallFrom:(NSString *)from withUUID:(NSUUID *)uuid {
CXHandle *callHandle = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:from];
CXHandleType type = [[from substringToIndex:1] isEqual:@"+"] ? CXHandleTypePhoneNumber : CXHandleTypeGeneric;
// lets replace 'client:' with ''
CXHandle *callHandle = [[CXHandle alloc] initWithType:type value:[from stringByReplacingOccurrencesOfString:@"client:" withString:@""]];

CXCallUpdate *callUpdate = [[CXCallUpdate alloc] init];
callUpdate.remoteHandle = callHandle;
Expand Down