Links

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. 1.
    Create an account for Firebase.
  2. 2.
    Create a new project from your Firebase console.
  3. 3.
    In your Project settings, add entries for your Android and iOS apps.
  4. 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. 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:
- (void)applicationDidBecomeActive:(UIApplication*) application {
[application registerUserNotificationSettings: [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil]];
[application registerForRemoteNotifications];
}
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:
package com.example;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import io.cobrowse.CobrowseIO;
public class FirebaseMessaging extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
CobrowseIO.instance().onPushNotification(remoteMessage.getData());
}
@Override
public void onNewToken(String token) {
CobrowseIO.instance().setDeviceToken(getApplication(), token);
}
}
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:
import CobrowseIO from 'cobrowse-sdk-react-native';
CobrowseIO.deviceToken = "<your FCM token>";

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:
[Export("applicationDidBecomeActive:")]
public void OnActivated(UIApplication application)
{
application.RegisterUserNotificationSettings(
UIUserNotificationSettings.GetSettingsForTypes(
UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert,
categories: null));
application.RegisterForRemoteNotifications();
}

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:
using System;
using Android.App;
using Android.Runtime;
using Firebase.Messaging;
using Xamarin.CobrowseIO;
namespace YourAppNamespace
{
[Service]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
public class FirebaseMessaging : FirebaseMessagingService
{
public FirebaseMessaging()
{
}
protected FirebaseMessaging(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
}
public override void OnMessageReceived(RemoteMessage remoteMessage)
{
CobrowseIO.Instance.OnPushNotification(remoteMessage.Data);
}
public override void OnNewToken(string token)
{
CobrowseIO.Instance.SetDeviceToken(Application, token);
}
}
}