@@ -97,11 +97,11 @@ Make sure you enabled the folowing in `Xcode` -> `Signing & Capabilities`:
97
97
98
98
99
99
100
- // ===== (THIS IS OPTIONAL) =====
100
+ // ===== (THIS IS OPTIONAL BUT RECOMMENDED ) =====
101
101
// --- register VoipPushNotification here ASAP rather than in JS. Doing this from the JS side may be too slow for some use cases
102
102
// --- see: https://github.com/react-native-webrtc/react-native-voip-push-notification/issues/59#issuecomment-691685841
103
103
[ RNVoipPushNotificationManager voipRegistration] ;
104
- // ===== (THIS IS OPTIONAL) =====
104
+ // ===== (THIS IS OPTIONAL BUT RECOMMENDED ) =====
105
105
106
106
107
107
@@ -224,10 +224,33 @@ class MyComponent extends React.Component {
224
224
225
225
...
226
226
227
- // --- or anywhere which is most comfortable and appropriate for you, usually ASAP
227
+ // --- anywhere which is most comfortable and appropriate for you,
228
+ // --- usually ASAP, ex: in your app.js or at some global scope.
228
229
componentDidMount () {
229
- VoipPushNotification .registerVoipToken (); // --- register token
230
230
231
+ // --- NOTE: You still need to subscribe / handle the rest events as usuall.
232
+ // --- This is just a helper whcih cache and propagate early fired events if and only if for
233
+ // --- "the native events which DID fire BEFORE js bridge is initialed",
234
+ // --- it does NOT mean this will have events each time when the app reopened.
235
+
236
+
237
+ // ===== Step 1: subscribe `register` event =====
238
+ // --- this.onVoipPushNotificationRegistered
239
+ VoipPushNotification .addEventListener (' register' , (token ) => {
240
+ // --- send token to your apn provider server
241
+ });
242
+
243
+ // ===== Step 2: subscribe `notification` event =====
244
+ // --- this.onVoipPushNotificationiReceived
245
+ VoipPushNotification .addEventListener (' notification' , (notification ) => {
246
+ // --- when receive remote voip push, register your VoIP client, show local notification ... etc
247
+ this .doSomething ();
248
+
249
+ // --- optionally, if you `addCompletionHandler` from the native side, once you have done the js jobs to initiate a call, call `completion()`
250
+ VoipPushNotification .onVoipNotificationCompleted (notification .uuid );
251
+ });
252
+
253
+ // ===== Step 3: subscribe `didLoadWithEvents` event =====
231
254
VoipPushNotification .addEventListener (' didLoadWithEvents' , (events ) => {
232
255
// --- this will fire when there are events occured before js bridge initialized
233
256
// --- use this event to execute your event handler manually by event type
@@ -244,20 +267,10 @@ class MyComponent extends React.Component {
244
267
}
245
268
}
246
269
});
247
-
248
- // --- onVoipPushNotificationRegistered
249
- VoipPushNotification .addEventListener (' register' , (token ) => {
250
- // --- send token to your apn provider server
251
- });
252
270
253
- // --- onVoipPushNotificationiReceived
254
- VoipPushNotification .addEventListener (' notification' , (notification ) => {
255
- // --- when receive remote voip push, register your VoIP client, show local notification ... etc
256
- this .doSomething ();
257
-
258
- // --- optionally, if you `addCompletionHandler` from the native side, once you have done the js jobs to initiate a call, call `completion()`
259
- VoipPushNotification .onVoipNotificationCompleted (notification .uuid );
260
- });
271
+ // ===== Step 4: register =====
272
+ // --- it will be no-op ( no event will be fired ) if you have subscribed before like in native side.
273
+ VoipPushNotification .registerVoipToken (); // --- register token
261
274
}
262
275
263
276
// --- unsubscribe event listeners
0 commit comments