Initiate sessions with push
For use with Android, iOS, React Native, and Xamarin SDKs only.
By default, Cobrowse Native SDKs for Android and iOS open a socket to handle incoming session requests.
You may optionally send new session requests over the native push channel. Cobrowse supports this configuration out of box using Firebase Cloud Messaging (FCM).
Setup your Firebase account:
    1.
    Create an account for Firebase.
    2.
    Create a new project from your Firebase console.
    3.
    In your Project settings, add entries for your Android and iOS apps.
    4.
    For iOS, you will need generate an APNs Authentication Key (recommended) or APNs Certificate from https://developer.apple.com. You may then upload it under Project Settings -> Cloud Messaging.
    5.
    Please generate a Firebase Server Key from Project Settings -> Cloud Messaging and enter it into your Firebase settings.
A few changes to native code as described below.
iOS
Android
React Native
Xamarin
If you are already using push notifications in your app, there is nothing further required on the native side.
If you are not already using push notifications in your app, please enable them under Capabilities in Xcode and request push permission from the user whenever is appropriate:
1
- (void)applicationDidBecomeActive:(UIApplication*) application {
2
[application registerUserNotificationSettings: [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil]];
3
[application registerForRemoteNotifications];
4
}
Copied!
You must first add Firebase Cloud Messaging (FCM) to your app. Please see FCM documentation at https://firebase.google.com/docs/cloud-messaging/android/client.
Next, whenever your device receives a registration token or push notification from FCM, pass that to the Cobrowse.io SDK, for example:
1
package com.example;
2
3
import com.google.firebase.messaging.FirebaseMessagingService;
4
import com.google.firebase.messaging.RemoteMessage;
5
6
import io.cobrowse.CobrowseIO;
7
8
public class FirebaseMessaging extends FirebaseMessagingService {
9
10
@Override
11
public void onMessageReceived(RemoteMessage remoteMessage) {
12
CobrowseIO.instance().onPushNotification(remoteMessage.getData());
13
}
14
15
@Override
16
public void onNewToken(String token) {
17
CobrowseIO.instance().setDeviceToken(getApplication(), token);
18
}
19
20
}
Copied!
You must first add Firebase Cloud Messaging (FCM) to your app. Please see FCM documentation at https://firebase.google.com/docs/cloud-messaging/android/client.
Next, whenever your device receives a registration token from FCM, pass that to the Cobrowse.io SDK, for example:
1
import CobrowseIO from 'cobrowse-sdk-react-native';
2
3
CobrowseIO.deviceToken = "<your FCM token>";
Copied!

Xamarin.iOS implementation

If you are already using push notifications in your app, there is nothing further required on the native side.
If you are not already using push notifications in your app, please enable them under Capabilities in the Xamarin.iOS app project and request push permission from the user whenever is appropriate:
1
[Export("applicationDidBecomeActive:")]
2
public void OnActivated(UIApplication application)
3
{
4
application.RegisterUserNotificationSettings(
5
UIUserNotificationSettings.GetSettingsForTypes(
6
UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert,
7
categories: null));
8
application.RegisterForRemoteNotifications();
9
}
Copied!

Xamarin.Android implementation

You must first add Firebase Cloud Messaging (FCM) to your app. Please see FCM documentation at https://docs.microsoft.com/en-us/xamarin/android/data-cloud/google-messaging/firebase-cloud-messaging.
Next, whenever your device receives a registration token or push notification from FCM, pass that to the Cobrowse.io SDK, for example:
1
using System;
2
using Android.App;
3
using Android.Runtime;
4
using Firebase.Messaging;
5
using Xamarin.CobrowseIO;
6
7
namespace YourAppNamespace
8
{
9
[Service]
10
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
11
public class FirebaseMessaging : FirebaseMessagingService
12
{
13
public FirebaseMessaging()
14
{
15
}
16
17
protected FirebaseMessaging(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
18
{
19
}
20
21
public override void OnMessageReceived(RemoteMessage remoteMessage)
22
{
23
CobrowseIO.Instance.OnPushNotification(remoteMessage.Data);
24
}
25
26
public override void OnNewToken(string token)
27
{
28
CobrowseIO.Instance.SetDeviceToken(Application, token);
29
}
30
}
31
}
Copied!
Last modified 1yr ago
Copy link