Push

Prev Next

Push

In Ncloud Chat, push notifications are a core function that informs you of important information or updates in real time. Through this push notifications service, you don't miss any important message even when the app is in the background or the device is not activated. The following describes the push notifications functions of Ncloud Chat.

Main functions of push notifications

  1. Real-time notification: chat-related notifications such as new messages, member changes, and event invitations are immediately sent to you.
  2. Customizable: you can customize the format and contents of the notifications suited for the application's requirements.
  3. Multiple platforms supported: it supports push notifications for various mobile operating systems such as iOS and Android to expand the user base.
  4. Battery and data efficiency: it minimizes battery consumption and data usage with the recent push technology and sends notifications efficiently.
  5. Interactive notification: you can include interactive components to allow you to respond in the notification itself directly. For example, you can reply directly to a message, or respond to an invitation.

Implementation methods of push notifications

To implement the push notifications service, Ncloud Chat API provides a few core components:

  • Register push tokens: you can register a push token of your device to the Ncloud Chat server to allow sending a notification to the corresponding device.
  • Manage notification settings: you can set whether you will receive a notification depending on your preference for notifications.
  • Backend integration: the server side can create and send push notifications in real time by integrating with the backend of Ncloud Chat.

Security and personal information protection

  • Data encryption: all push notifications are encrypted during transfer and protected from external access.
  • Compliance with the Personal Information Protection Act: Ncloud Chat takes users' personal information protection very seriously, and provides notification services in accordance with related laws and regulations.

Through the push notifications function, Ncloud Chat induces user participation, increases the application usage rate, and enhances user experience. You can be connected anytime, anywhere, so you don't miss important communication.

Android(Kotlin)

After adding the Android app in Firebase Console, download the "google-services.json" file and place it in the root folder of the project's app module.

After adding the file, include the following content in bundle.gradle.kts.

plugins {
...
    id("com.google.gms.google-services")
...
}
dependencies {
...
    implementation("com.google.firebase:firebase-messaging-ktx:23.2.1")
...
}

Requests a push permissions pop-up.

import com.nbase.sdk.Permission

NChat.setEnablePush(true)
NChat.requestPermission(this, Permission.NOTIFICATION)
// Ensure this is called before initialization.

Call setPushState to configure push notification settings after connecting.

NChat.setPushState(PushState([PUSH], [AD], [NIGHT])) { state, e ->
    if (e != null) {
        // Error
    } else {
        // Success
    }
}
ID Type Description
push boolean Push notifications On/Off (true = On)
ad boolean Must be called with true to enable push notifications
night boolean Night push notifications On/Off

iOS(Swift)

Adding app push notification permission. Navigate to the Signing & Capabilities of the target, and select + Capability > Push Notifications in the upper left to add it.
ncloudchat-iOS-Push01.png

Create AppDelegate.swift

import UIKit
import NChat

class AppDelegate: NSObject, UIApplicationDelegate {
  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Request push notification permission
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
            print("Permission granted: \(granted)")
        }
        
        UNUserNotificationCenter.current().delegate = self
        application.registerForRemoteNotifications()
        
        return true
    }

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        // Convert APNs token to string
        let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
        let token = tokenParts.joined()
        
        // To receive push in a sandbox environment, set sandbox: true
        NChat.setPushToken(token: token, sandbox: false)
    }
}

Call setPushState to configure push notification settings after connecting.

NChat.setPushState(push: true, ad: true, night: true) { result in
    switch(result)
    {
    case .success(let status) :
        // Success
        break;
    case .failure(let error) :
        // Failed
        break;
    }
}
ID Type Description
push boolean Push notifications On/Off (true = On)
ad boolean Must be called with true to enable push notifications
night boolean Night push notifications On/Off