LogoLogo
  • A better way to do...stuff!
  • How we build the app
    • Overview
  • Documentation
    • Draftbit
      • Using Live Preview
      • Workspaces and Billing
      • Introduction to the Builder
      • Layout
      • Intro to Navigation
      • Fetching Data
      • Direct Integrations
      • FAQs
      • Draftbit
      • Draftbit
      • Custom Blocks
      • Borders, Background, and Elevation
      • Actions
      • Custom Screen Code
      • Exporting and Publishing Your Project
      • Sharing Your Project Online
      • Publishing Your App as a PWA
      • Stack Navigator
      • Tab Navigator
      • Draftbit
      • Draftbit
      • Basic
      • Media
      • REST Services & Endpoints
      • REST API Integrations
      • Themes & Styling
      • Submitting Data
      • Draftbit
      • Draftbit
    • Xano
      • resources-and-tips-1
        • 🎞️ Xano Video Tutorials
        • 🤝Community Corner
        • 💰Share Xano. Make money
      • FAQ
      • getting-started
        • ⚡ Jumpstart
        • 🎞️ The Xano Interface
      • instances
        • What is an Instance?
        • Early Access Instance
        • Upgrading an Instance
        • Sharing
        • Bandwidth Usage
        • API Rate Limit
      • What is a Workspace?
      • Dashboard
      • Database
      • Airtable Import
      • API
      • Library
      • Marketplace
      • Settings
      • authentication
        • Authentication
        • Sign-up & Log in
      • data-manipulation
        • The Function Stack
        • Addons (GraphQL-Like)
        • The Expression Builder
        • External Query Manipulation
        • Timestamp
        • Filters
        • Images
    • Expo
      • Creating your first build - Expo Documentation
    • Kommunicate
      • Installation
      • Installation
      • Installation
      • Installation
      • Installation
      • Flutter Installation
      • Installation
      • Zapier Integration
      • Authentication
      • CMS Installation
      • Authentication
      • Conversation
      • Conversation Assignment
      • Customization
      • Localization
      • Logout
      • Web Troubleshooting
      • Installation
      • Authentication
      • Push Notification
      • Conversation
      • Customization
      • Localization
      • Logout
      • Installation
      • Authentication
      • Push Notification
      • Conversation
      • Customization
    • Formito
      • basics
        • Getting Started
        • Variables
        • Are you GDPR ready?
        • How to prefill the values of my chatbot?
      • connect
        • How to connect Formito to Zapier?
      • convert
        • How to convert old formito chatbots to the new version?
        • How to convert Google Forms into a chatbot?
        • How to convert a Monday.com board to a chatbot?
        • How to create chatbot from QuickBase table?
      • guide
        • How to add my chatbot to WordPress?
        • How to create a chatbot for Zendesk?
      • shopify
        • How to embed my chatbot into a Shopify page?
        • How to display Formito chatbot on bottom corner of my Shopify store?
        • How to open my chatbot after clicking on links or buttons?
    • Stonly
  • Flex Stuff
    • App
    • APIs
    • Database
    • Website
    • Design
    • Style Guide
  • Content
    • Guides
    • ChatBots
    • Blogs
    • Whitepapers
  • Company
    • About us
    • Brand
    • Roadmap
    • Policies
  • Flex Together
    • Overview
    • Fair Finance
Powered by GitBook
On this page
  • Push Notification Setup
  • a) Send device token to Kommunicate server:
  • b) Receiving push notification:
  • c) Handling app launch on notification click:
  • d) AppDelegate changes for foreground notification:
  • e) Save Context when app terminates:
  • Certificates

Was this helpful?

  1. Documentation
  2. Kommunicate

Push Notification

Push Notification Setup

Add import statement in AppDelegate file to access the methods

import Kommunicate

a) Send device token to Kommunicate server:

In your AppDelegate’s didRegisterForRemoteNotificationsWithDeviceToken method send device token registration to Kommunicate server after you get deviceToken from APNS. Sample code is as below:

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
{

    print("DEVICE_TOKEN_DATA :: \(deviceToken.description)")  

    var deviceTokenString: String = ""
    for i in 0..count
    {
        deviceTokenString += String(format: "%02.2hhx", deviceToken[i] as CVarArg)
    }
    print("DEVICE_TOKEN_STRING :: \(deviceTokenString)")

    if (KMUserDefaultHandler.getApnDeviceToken() != deviceTokenString)
    {
        let kmRegisterUserClientService: KMRegisterUserClientService = KMRegisterUserClientService()
        kmRegisterUserClientService.updateApnDeviceToken(withCompletion: deviceTokenString, withCompletion: { (response, error) in
            print ("REGISTRATION_RESPONSE :: \(String(describing: response))")
        })
    }
}

b) Receiving push notification:

Once your app receives notification, pass it to Kommunicate handler for chat notification processing.

Add the following code in AppDelegate class, this function will be called after the app launch to register for push notifications.

func registerForNotification() {
    UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in
        if granted {
            DispatchQueue.main.async {
                UIApplication.shared.registerForRemoteNotifications()
            }
        }
    }
}



    UNUserNotificationCenter.current().delegate = self
    registerForNotification()

    KMPushNotificationHandler.shared.dataConnectionNotificationHandlerWith(Kommunicate.defaultConfiguration, Kommunicate.kmConversationViewConfiguration)
    let kmApplocalNotificationHandler: KMAppLocalNotification =  KMAppLocalNotification.appLocalNotificationHandler()
    kmApplocalNotificationHandler.dataConnectionNotificationHandler()

c) Handling app launch on notification click:

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    let service = KMPushNotificationService()
    let dict = notification.request.content.userInfo
    guard !service.isKommunicateNotification(dict) else {
        service.processPushNotification(dict, appState: UIApplication.shared.applicationState)
        completionHandler([])
        return
    }
    completionHandler([.sound, .badge, .alert])
}

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    let service = KMPushNotificationService()
    let dict = response.notification.request.content.userInfo
    if service.isApplozicNotification(dict) {
        service.processPushNotification(dict, appState: UIApplication.shared.applicationState)
    }
    completionHandler()
}

d) AppDelegate changes for foreground notification:

The following functions will be called by AppDelegate when the app comes to foreground(active) mode, add this anywhere inside the AppDelegate class.

An optional step that is only required if you want to reset the app icon badge count after a user opens the app.

func applicationWillEnterForeground(_ application: UIApplication) {
    print("APP_ENTER_IN_FOREGROUND")
    UIApplication.shared.applicationIconBadgeNumber = 0
}

e) Save Context when app terminates:

 func applicationWillTerminate(application: UIApplication) {
     KMDBHandler.sharedInstance().saveContext()
 }

Certificates

a) Upload development and distribution APNs certificates

b) Updating Capabilities

Post setting up APNs, the next step is to enable “Push Notifications” and “Background Modes” within your project.

  1. Click on your project, select it from TARGETS.

  2. Next select ‘Signing & Capabilities’ section.

    • Click on “+Capability”

    • Search and select “Push Notifications”

    • Click on “+Capability” again

    • Search and select “Background Modes”

Enable “Background Fetch” and “Remote notifications” under “Background Modes” list

Following screenshot would be of help.

PreviousAuthenticationNextConversation

Last updated 4 years ago

Was this helpful?

Add the following code anywhere inside the AppDelegate class, refer to for the better understanding.

You can check the sample AppDelegate file .

Upload development and distribution APNs certificates on , this will allow Kommunicate to send the notification for new messages to your mobile app.

this sample
here
Kommunicate dashboard