voximplant / react-native-voximplant

Voximplant mobile SDK for React Native (iOS/Android)
http://voximplant.com
205 stars 39 forks source link

PushKit and handling call IOS #73

Closed Linoa65 closed 5 years ago

Linoa65 commented 5 years ago

Hello !

I need to implement the PushKit calls for my app with VoxImplant. For android, I'm able to get my message, run the app, login to my services then catch the call and display it with no problems. But for IOS, I have absolutely no idea to how to implement it. I tried to look at the demo but it use "react-native-notifications", which seems deprecated and maybe unable to work in next versions of react-native.

I'm actually able to get remote notifications from firebase (for example, new chat message from user, or displaying various informations) on IOS, so all the configurations for enable Push Notifications are OKs. So, what is the best practice to implement PushNotification for handling calls in IOS ? Because I need to the app to begin some work when the notification is displayed, to allow user to click to the notification and put app to foreground to display the call.

Sincerely Florient

YuliaGrigorieva commented 5 years ago

Hello!

To get VoIP push notifications for incoming calls you need some module that provides PushKit API. RNFirebase currently does not provide such APIs, that's why we use react-native-notifications module in the demo project. However it is up to you to choose the module with PushKit support.

Could you please provide more details about the issues you faced while working with react-native-notifications module?

Best regards, Yulia Grigorieva

Linoa65 commented 5 years ago

Hello !

Thanks for your fast answer ! :) I try to understand the logic to implement, and with RNNotifications, I currently successfully get my push token (with event 'remoteNotificationsRegistered'), but nothing more happens. And I can't know if the message is sent by VI Scenario but not catch, or not sent at all.

I follow all steps to add my certificate to VI Control Panel in Development mode, so I think this works.

Since you did the react-native-demo, the module react-native-notifications changes. This is a snippet of what I add after my main method in AppDelegate.m

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification
{
  [[RNNRouter sharedInstance] application:application didReceiveRemoteNotification:notification fetchCompletionHandler:nil];
}

// PushKit API Support
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
  [[RNNRouter sharedInstance] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type
{
  [[RNNRouter sharedInstance] didUpdatePushCredentials:credentials forType:type];
}

- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type
{
  [[RNNRouter sharedInstance] application:nil didReceiveRemoteNotification:payload.dictionaryPayload fetchCompletionHandler:nil];
}

And for RN side I just called

NotificationsIOS.consumeBackgroundQueue();
NotificationsIOS.addEventListener("remoteNotificationsRegistered", this.onPushKitRegistered.bind(this));
NotificationsIOS.addEventListener("notificationReceivedBackground", this.onNotificationReceivedBackground.bind(this));
NotificationsIOS.addEventListener("notificationReceivedForeground", this.onNotificationReceivedForeground.bind(this));

Like I said, only onPushKitRegistered is called.

Sincerely Florient

YuliaGrigorieva commented 5 years ago

Hello!

onPushKitRegistered method should provide token for VoIP push notifications: https://github.com/voximplant/react-native-demo/blob/44b5d5c92a8ba3f36f1964be06bad935722c8448/src/manager/PushManager.ios.js#L27-L30

When you need to provide this token to the Voximplant React Native SDK. In the demo app it is done after successful login: https://github.com/voximplant/react-native-demo/blob/44b5d5c92a8ba3f36f1964be06bad935722c8448/src/manager/LoginManager.js#L187 https://github.com/voximplant/react-native-demo/blob/44b5d5c92a8ba3f36f1964be06bad935722c8448/src/manager/LoginManager.js#L134

Please check your code and ensure that push token is registered in the SDK.

If you do not receive push notifications for incoming calls after that, please check the following:

  1. you have added a valid VoIP push certificate to the Voximplant Control Panel. Please take a look at this tutorial: https://voximplant.com/docs/references/iossdk/push-notifications-for-ios
  2. you see your push token in the call session logs in the Voximplant Control Panel. Search for push wakeup result: line in the logs and ensure that the result of sending push notification is success in the logs

Best regards, Yulia Grigorieva

Linoa65 commented 5 years ago

Thank you,

I correctly registered to the token, I think the RN part is okay, but I saw in log session that the push wakeup result gets an error "Certificate not found". I followed all steps, and tried to add it as Production, and Development but the error still the same. I will try to regenerate my certificate, then will see.

Sincerely Florient

Linoa65 commented 5 years ago

Okay I got know BadDeviceToken, I'm progressing :)

Linoa65 commented 5 years ago

I got now result success from VI logs when sending the push notification.

Linoa65 commented 5 years ago

Thanks for everything, I now receive my notification on IOS devices.

My last problem is related to notifications background, that be triggered only when I open my app. It seems this event is not triggered if "{content-available: 1}" is not added to the notification sent. I try to found a solution.

Great work, Sincerely, Florient

YuliaGrigorieva commented 5 years ago

Not sure that I understand your current issue correctly.

However please note that the correct workflow with the VoIP push notifications is the following:

  1. receive VoIP push notification in the application
  2. connect and login to the Voximplant Cloud (if the client is not logged in)
  3. call Client.handlePushNotification method
  4. Wait for IncomingCall event
  5. Show incoming call notification (via local notification, callkit or anything else)
  6. Let user answer or reject this call

Best regards, Yulia Grigorieva

Linoa65 commented 5 years ago

My actual problem is that the push notification received on my IOS device is handled only after I open my app. The workflow works, but to run it, I need to open my app after call is sent from another device, then the notificationReceivedBackground will be raised.

I tried to send at the same time a remote notification from firebase cloud function, with the "content-available: 1", and it correctly wake up my app to handle the notification.

Sincerely Florient

YuliaGrigorieva commented 5 years ago

Hello!

I have just tried to reproduce the issue with our demo project and it is not reproducible. After putting the application to the background, it shows local notification for a new incoming call.

Could you please try reproducing the issue on the demo project and let me know the results?

Best regards, Yulia Grigorieva

Linoa65 commented 5 years ago

Hello !

I tried with the demo project, I'm able to connect and get calls, but if the app goes in background, it ask me to relog when I open back the demo app. If I receive a call when app not in foreground (background or dead state) there is no notifications.

I check the logs in control panel, and it seems my notification is correctly sent:

push wakeup result: BObrN2kUqQXR2iFkD1m6uTapTx13@vocal.sweetnewworld.voximplant.com > {android={result=no tokens found}, ios={a4437bafe12e09bd99f5ade340f050bae89003f2a0ef67b53038f6cddf7c2e70={result=success}, 15c259a2ffb278da77b2ba1c969b199ad6bd6ba15b8ed42d0a285f9f8ad41108={result=success}}}

Sincerely Florient

Linoa65 commented 5 years ago

Ok, now I get an error on notifications sent on VI side :

a7ecf81be9a9a21729f7024fe8ff84b5c420035508cc48079bd3bded52e1361a={result=reject : TopicDisallowed}}
YuliaGrigorieva commented 5 years ago

Hello!

Have you changed something? Have you changed the certificates in the Voximplant Control Panel?

{result=success} - does not mean that the push notification was received on a device. It means that the push notification was successfully sent to the APNS (i.e. APNS excepted it). To check that the push notification is received on the device, you need to check the log in the Xcode output. I recommend you add some logs to print push notification payload in the method where you handle it and also please ensure that you have a log message similar to this one:

2019-04-05 18:52:32.441+0300 VoximplantDemo #VI/I [VIClientMo] > handlePushNotification: {
    voximplant =     {
        addr = "....";
        callid = "....";
        "display_name" = xxxx;
        sessionid = ".....";
        userid = "....";
    };
} 

Best regards, Yulia Grigorieva

Linoa65 commented 5 years ago

Thank you, I changed nothing, there is no reason to send me an error now and not before... I will regenerate certificates then try again, i will tell you the results.

Sincerely, Florient

Linoa65 commented 5 years ago

After regenerate my certificate, the problem still the same, I always get the error "TopicDisallowed" from VI logs. Did you know why this error is produced ?

I was able to correctly handle my notifications this morning and it suddenly broke without changing on VI side. Is this a limitation of apple (due to my repeated tests on notifications) ?

YuliaGrigorieva commented 5 years ago

Hello!

According to APNS documentation TopicDisallowed means 'Pushing to this topic is not allowed.' In APNS errors 'topic' generally means App Bundle ID.

According to that please check that:

  1. you have not changed the bundle id of your application (in Xcode project)
  2. you have enabled push notifications in your project settings (capabilities).
  3. From push notification setup tutorial:

    Enable Push Notifications and following Background Modes: "Audio, AirPlay, and Picture in Picture", "Voice over IP" (if you need to handle calls), "Background fetch" and "Remote notifications"

Please ensure that everything listed above is enabled.

Best regards, Yulia Grigorieva

Linoa65 commented 5 years ago

Hello !

Finally I find my solution, I regenerate a certificate, it seems VoIP push notifications are not handle with service push certificate. We need to use VoIP certificate to correctly handle the VoIP notifications.

Thank you for everything, I close the issue. Feel free to ask question or reopen if someone else have issue with that.

Sincerely Florient