Skip to content

Commit 303b39c

Browse files
authored
readme: add note for ios 13 with CallKit
1 parent c5d64fd commit 303b39c

File tree

1 file changed

+80
-33
lines changed

1 file changed

+80
-33
lines changed

README.md

Lines changed: 80 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,55 @@ To understand the benefits of **Voip Push Notification**, please see [VoIP Best
2020
* 1.1.0+ ( RN 40+ )
2121
* 2.0.0+ (RN 60+)
2222

23-
If you're using React Native >= 0.40, make sure to use react-native-voip-push-notification >= 1.1.0
23+
## !!IMPORTANT NOTE!!
24+
25+
#### You should use this module with CallKit:
26+
27+
Now Apple forced us to invoke CallKit ASAP when we receive voip push on iOS 13 and later, so you should check [react-native-callkeep](https://github.com/react-native-webrtc/react-native-callkeep) as well.
28+
29+
#### Please read below links carefully:
30+
31+
https://developer.apple.com/documentation/pushkit/pkpushregistrydelegate/2875784-pushregistry
32+
33+
> When linking against the iOS 13 SDK or later, your implementation of this method must report notifications of type voIP to the CallKit framework by calling the reportNewIncomingCall(with:update:completion:) method
34+
>
35+
> On iOS 13.0 and later, if you fail to report a call to CallKit, the system will terminate your app.
36+
>
37+
> Repeatedly failing to report calls may cause the system to stop delivering any more VoIP push notifications to your app.
38+
>
39+
> If you want to initiate a VoIP call without using CallKit, register for push notifications using the UserNotifications framework instead of PushKit. For more information, see UserNotifications.
40+
41+
#### Issue introduced in this change:
42+
43+
When received VoipPush, we should present CallKit ASAP even before RN instance initialization.
44+
45+
This breaks especially if you handled almost call behavior at js side, for example:
46+
Do-Not-Disturb / check if Ghost-Call / using some sip libs to register or waiting invite...etc.
47+
48+
Staff from Apple gives some advisions for these issues in the below discussion:
49+
https://forums.developer.apple.com/thread/117939
50+
51+
#### you may need to change your server for APN voip push:
52+
53+
Especially `apns-push-type` value should be 'voip' for ios 13
54+
And be aware of `apns-expiration`value, adjust according to your call logics
55+
56+
https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns
2457

2558
## Installation
2659

2760
```bash
2861
npm install --save react-native-voip-push-notification
62+
# --- if using pod
63+
cd ios/ && pod install
2964
```
3065

31-
### iOS
32-
3366
The iOS version should be >= 8.0 since we are using [PushKit][1].
3467

3568
#### Enable VoIP Push Notification and Get VoIP Certificate
3669

3770
Please refer to [VoIP Best Practices][2].
3871

39-
**Note**: Do NOT follow the `Configure VoIP Push Notification` part from the above link, use the instruction below instead.
40-
4172
#### AppDelegate.m Modification
4273

4374
```objective-c
@@ -64,37 +95,59 @@ Please refer to [VoIP Best Practices][2].
6495
[RNVoipPushNotificationManager didUpdatePushCredentials:credentials forType:(NSString *)type];
6596
}
6697

67-
// Handle incoming pushes
98+
// Handle incoming pushes (for ios <= 10)
6899
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type {
69-
// Process the received push
70100
[RNVoipPushNotificationManager didReceiveIncomingPushWithPayload:payload forType:(NSString *)type];
71101
}
72102

103+
// --- Handle incoming pushes (for ios >= 11)
104+
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void (^)(void))completion {
105+
106+
// --- Process the received push
107+
[RNVoipPushNotificationManager didReceiveIncomingPushWithPayload:payload forType:(NSString *)type];
108+
109+
// --- NOTE: apple forced us to invoke callkit ASAP when we receive voip push
110+
// --- see: react-native-callkeep
111+
if (@available(iOS 13, *)) {
112+
// --- Retrieve information from your voip push payload
113+
NSString *uuid = payload.dictionaryPayload[@"uuid"];
114+
NSString *callerName = [NSString stringWithFormat:@"%@ (Connecting...)", payload.dictionaryPayload[@"callerName"]];
115+
NSString *handle = payload.dictionaryPayload[@"handle"];
116+
117+
[RNCallKeep reportNewIncomingCall:uuid handle:handle handleType:@"generic" hasVideo:false localizedCallerName:callerName fromPushKit: YES];
118+
}
119+
120+
completion();
121+
}
73122
...
74123

75124
@end
76125

77126
```
78127
79-
#### Add PushKit Framework
128+
## Linking
80129
81-
- In your Xcode project, select `Build Phases` --> `Link Binary With Libraries`
82-
- Add `PushKit.framework`
130+
On RN60+, auto linking with pod file should work.
131+
Or you can try below:
83132
84-
#### Add RNVoipPushNotification
133+
## Linking Manually:
85134
86-
On RN60+, auto linking with pod file should work. Or you can try below:
135+
### Add PushKit Framework
87136
137+
- In your Xcode project, select `Build Phases` --> `Link Binary With Libraries`
138+
- Add `PushKit.framework`
139+
140+
### Add RNVoipPushNotification
88141
89-
##### Option 1: Use [rnpm][3]
142+
#### Option 1: Use [rnpm][3]
90143
91144
```bash
92145
rnpm link react-native-voip-push-notification
93146
```
94147

95148
**Note**: If you're using rnpm link make sure the `Header Search Paths` is `recursive`. (In step 3 of manually linking)
96149

97-
##### Option 2: Manually
150+
#### Option 2: Manually
98151

99152
1. Drag `node_modules/react-native-voip-push-notification/ios/RNVoipPushNotification.xcodeproj` under `<your_xcode_project>/Libraries`
100153
2. Select `<your_xcode_project>` --> `Build Phases` --> `Link Binary With Libraries`
@@ -116,34 +169,29 @@ class MyComponent extends React.Component {
116169

117170
...
118171

119-
componentWillMount() { // or anywhere which is most comfortable and appropriate for you
172+
componentDidMount() { // or anywhere which is most comfortable and appropriate for you
120173
VoipPushNotification.requestPermissions(); // --- optional, you can use another library to request permissions
121174
VoipPushNotification.registerVoipToken(); // --- required
122175

123176
VoipPushNotification.addEventListener('register', (token) => {
124-
// send token to your apn provider server
177+
// --- send token to your apn provider server
178+
});
179+
180+
VoipPushNotification.addEventListener('localNotification', (notification) => {
181+
// --- when user click local push
125182
});
126183

127184
VoipPushNotification.addEventListener('notification', (notification) => {
128-
// register your VoIP client, show local notification, etc.
129-
// e.g.
130-
this.doRegister();
185+
// --- when receive remote voip push, register your VoIP client, show local notification ... etc
186+
//this.doRegisterOrSomething();
131187

132-
/* there is a boolean constant exported by this module called
133-
*
134-
* wakeupByPush
135-
*
136-
* you can use this constant to distinguish the app is launched
137-
* by VoIP push notification or not
138-
*
139-
* e.g.
140-
*/
188+
// --- This is a boolean constant exported by this module
189+
// --- you can use this constant to distinguish the app is launched by VoIP push notification or not
141190
if (VoipPushNotification.wakeupByPush) {
142-
// do something...
191+
// this.doSomething()
143192

144-
// remember to set this static variable to false
145-
// since the constant are exported only at initialization time
146-
// and it will keep the same in the whole app
193+
// --- remember to set this static variable back to false
194+
// --- since the constant are exported only at initialization time, and it will keep the same in the whole app
147195
VoipPushNotification.wakeupByPush = false;
148196
}
149197

@@ -161,7 +209,6 @@ class MyComponent extends React.Component {
161209
});
162210
});
163211
}
164-
165212
...
166213

167214
}

0 commit comments

Comments
 (0)