enablePush()

This API can be used to extract and pass over your mobile app's push notification data to the embedded Zoho SalesIQ SDK.

Parameters

  • Regid: The given device token.
  • Bool: (True/False) If the value is set to "True" then the devices will be displayed in the SalesIQ web SDK section to send and test the push notification in respective mode.
  • mode: .sandbox/.production

To set up push notification:

Step 1. To enable push notification in the SalesIQ SDK, conform AppDelegate to the UNUserNotificationCenterDelegate protocol and add the following block of code.

Copiedif #available(iOS 10.0, *) {
            let center = UNUserNotificationCenter.current()
            center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in
                center.delegate = self
                print("in del")
            }
            let categoryOptions = UNNotificationCategoryOptions(rawValue: 0)
           
            let reply = UNTextInputNotificationAction(identifier: "Reply", title:"Reply", options: [], textInputButtonTitle:"Send", textInputPlaceholder: "Message")
            let chatGrpMsgCategory_10 = UNNotificationCategory(identifier: "GRPCHATMSG", actions: [reply], intentIdentifiers: [], options: [categoryOptions])
            UNUserNotificationCenter.current().setNotificationCategories([chatGrpMsgCategory_10])
            application.registerForRemoteNotifications()
        } else {
            let settings:UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories:nil )
            application.registerUserNotificationSettings(settings)
        }

Step 2. To enable push notification, select the mode: APNSMode.sandbox or APNSMode.production, and include the following snippet in the application: didRegisterForRemoteNotificationsWithDeviceToken.

Note: At this stage, you should make sure that you have enabled the Push Notification capability in Xcode.

Copiedfunc application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        let deviceTokenString = deviceToken.reduce("", {$0 + String(format:
            "%02X", $1)})
        ZohoSalesIQ.enablePush(deviceTokenString, isTestDevice: true,mode: APNSMode.sandbox)
    }

Step 3.  In your App Delegate file, include the following snippet to enable the reply option to the corresponding received notification. Learn more about the Notification.setAction() and Notification.getPayload() here.

Copied@available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter,didReceive
        response: UNNotificationResponse,
                                withCompletionHandler completionHandler: @escaping () -> Void)
    {
        
        if ZohoSalesIQ.isMobilistenNotification(response.notification.request.content.userInfo){
            switch response.actionIdentifier {
            case "Reply":
                ZohoSalesIQ.handleNotificationAction(response.notification.request.content.userInfo, response: (response as? UNTextInputNotificationResponse)?.userText)
                
            default: break
            }
            if response.actionIdentifier == UNNotificationDefaultActionIdentifier{
                ZohoSalesIQ.processNotificationWithInfo(response.notification.request.content.userInfo)
                //When using the .app in NotificationAction in Notification.setAction() API use the Notification.getPayload() API to details about the notification
            }
        }
        completionHandler()
    }

Step 4.  You can easily test if your push notification is working in the app.

  • To test manually, go to Settings > Brands > Select the brand > Installation > iOS > sandbox.
  • Enter the message and send it.
  • You will now receive a notification on your mobile phone.

Learn more about the Notification.setAction() and Notification.getPayload() here.