Skip to main content
To enable Skara Chat SDK push notifications, you first need to create a private key, upload it to the Salesmate (Web app >> Chat >> Chat Settings >> Installation >> iOS), and enter details about your app.

Topics covered:

Create a Private Key

Using these instructions, create and download a private key with APNs enabled. Note the Key ID for the next step. Alternatively, use an existing private key with APNs enabled.

Enable in Skara Chat SDK

Go to your Chat Settings and select Installation > iOS. In the “Enable Push Notifications” section:
  • Upload the .p8 file you just created
  • Enter the Key ID from Step 1
  • Enter the Bundle ID for the app you want to send notifications to
  • Enter the Apple team ID
  • Click Save Enable Push Notifications To send push notifications through Skara Chat SDK, add the .p8 file, Key ID, Bundle ID, and Apple team ID:
Enable Push Notifications

Register Device Tokens

To enable your users to receive push notifications from Salesmate Chat via Skara Chat SDK for iOS, you must request permission to send push notifications and register the device token of your user in your AppDelegate. Objective-C
- (void)application:(UIApplication *)application 
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

    NSString *deviceTokenString = [[[[deviceToken description]
        stringByReplacingOccurrencesOfString:@"<" withString:@""]
        stringByReplacingOccurrencesOfString:@">" withString:@""]
        stringByReplacingOccurrencesOfString:@" " withString:@""];

    [SalesmateChat sendDeviceTokenWith:deviceTokenString];
}
Swift
func application(_ application: UIApplication,
                 didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {

    let deviceTokenString = deviceToken.reduce("") { $0 + String(format: "%02X", $1) }

    SalesmateChat.sendDeviceToken(with: deviceTokenString)
}
At this stage, you should also ensure that you have enabled the Push Notifications and Background Modes capability and enabled Remote notifications in Xcode. Enable Push Notifications and Background Modes

Handling Salesmate Chat Push Notifications

Handle Salesmate Chat SDK push notifications manually in didReceiveNotificationResponse in your UNUserNotificationCenterDelegate: Objective-C
- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
 didReceiveNotificationResponse:(UNNotificationResponse *)response 
          withCompletionHandler:(void (^)(void))completionHandler {

    NSDictionary *userInfo = response.notification.request.content.userInfo;

    if (userInfo != nil) {
        if ([SalesmateChat isSalesmateChatSDKPushNotificationWithUserInfo:userInfo]) {
            [SalesmateChat handlePushNotificationWithUserInfo:userInfo];
            return;
        }
    }

    completionHandler();
}
Swift
func userNotificationCenter(_ center: UNUserNotificationCenter,
                            didReceive response: UNNotificationResponse,
                            withCompletionHandler completionHandler: @escaping () -> Void) {

    let dict = response.notification.request.content.userInfo as! [String: AnyObject]

    if SalesmateChat.isSalesmateChatSDKPushNotification(userInfo: dict) {
        SalesmateChat.handlePushNotification(userInfo: dict)
        return
    }

    completionHandler()
}
Handle Salesmate Chat SDK push notifications manually in willPresentNotification in your UNUserNotificationCenterDelegate: Objective-C
- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
       willPresentNotification:(UNNotification *)notification 
         withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {

    NSDictionary *userInfo = notification.request.content.userInfo;

    if (userInfo != nil) {
        if ([SalesmateChat isSalesmateChatSDKPushNotificationWithUserInfo:userInfo]) {
            [SalesmateChat handlePushNotificationWithUserInfo:userInfo];
            return;
        }
    }

    completionHandler(UNNotificationPresentationOptionAlert);
}
Swift
func userNotificationCenter(_ center: UNUserNotificationCenter,
                            willPresent notification: UNNotification,
                            withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {

    let dict = notification.request.content.userInfo as! [String: AnyObject]

    if SalesmateChat.isSalesmateChatSDKPushNotification(userInfo: dict) {
        SalesmateChat.handlePushNotification(userInfo: dict)
        return
    }

    completionHandler([.alert, .sound, .badge])
}