Push Notification

Kindly register for remote notification by conforming to the following delegates in the AppDelegate UNUserNotificationCenterDelegate. Call the below methods when an APNS token gets updated.

Note: Please upload your APNS and VOIP Certificate to our Console. To know more how to generate and upload APNS and VOIP Certificate Click Here

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// APNS Token Update
VOIPManager.sharedInstance.savePushToken(token: token)
VOIPManager.sharedInstance.updateDeviceToken()
}
ArgumentDescription
TOKENApns Token

App Group Id#

To receive messages in the background or in the killed state, You need to enable app group container ID. And pass in below method.

In order to access data between app and notification extension, enabling app group is mandatory to access user defaults and database in container.

Capabilities

Process push notification request#

let BASE_URL = "https://api-preprod-sandbox.mirrorfly.com/api/v1/"
let LICENSE_KEY = "xxxxxxxxxxxxxxxxxxxxxx"
let CONTAINER_ID = "xxxxxxxxxxxxxxxxxxxxxx"

Parameter Description#

FunctionParameter TypeDescription
CONTAINER_IDStringCreate App groups and assign the obtained group container id. SDK uses this string to create the path for the local storage.
caution

In order your changing existing app group container may occur data loss.

Need to set CONTAINER_ID in Appdeleagte class. Thus, we utilize the usage of the ChatSDK builder class making the data available to access user defaults and database in container for UNNotificationServiceExtension.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
try? ChatSDK.Builder
.setAppGroupContainerID(containerID: CONTAINER_ID)
.setLicenseKey(key: LICENSE_KEY)
.isTrialLicense(isTrial: true)
.setDomainBaseUrl(baseUrl: BASE_URL)
.buildAndInitialize()
}

Re-initialize the ChatSDK builder in didReceive method of the UNNotificationServiceExtension delegate.

In class that extends the UNNotificationServiceExtension after validating whether the received payload is for Chat or not, call the below method to process the request further.

func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
try? ChatSDK.Builder.setAppGroupContainerID(containerID: CONTAINER_ID)
.isTrialLicense(isTrial: !IS_LIVE)
.setLicenseKey(key: LICENSE_KEY)
.setDomainBaseUrl(baseUrl: BASE_URL)
.buildAndInitialize()
ChatSDK.Builder.initializeDelegate()
NotificationMessageSupport.shared.didReceiveNotificationRequest("NOTIFICATION_CONTENT", "COMPLETION_BLOCK")
}
ArgumentTypeDescription
NOTIFICATION_CONTENTUNMutableNotificationContentNotification request content
COMPLETION_BLOCK(UNMutableNotificationContent?, ChatMessage?) -> VoidCompletion Block
setAppGroupContainerIDStringPass group container id of the project that stores UserDefaults and Database

Notification