GameChat Docs
  • Overview
  • Getting Started
  • Basics
    • Game Chat (V2)
      • Game Chat(한국어)
        • Game Chat 사용 준비
        • Game Chat 시작
          • Game Chat 운영 및 관리
          • Unity SDK
        • OpenAPI
          • 채널 생성
          • 채널 수정
          • 채널 삭제
        • Game Chat 리소스 관리
        • Game Chat 릴리즈 노트
      • Game Chat(English)
        • Prerequisites for using Game Chat
        • Getting started with Game Chat
          • Game Chat operation and management
          • Unity SDK
        • OpenAPI
          • Channel creation API
          • Channel edit
          • Channel deletion API
        • Game Chat resource management
        • Game Chat release notes
      • Game Chat(日本語)
        • Game Chat を使用する前に
        • Game Chat を開始する
          • Game Chat の運用と管理
          • Unity SDK
        • OpenAPI
          • チャンネル作成API
          • チャネルの修正
          • チャンネル削除API
        • Game Chatのリソース管理
        • Game Chat のリリースノート
      • Game Chat(中文)
        • Game Chat使用前准备
        • 启动Game Chat
          • Game Chat运营和管理
          • Unity SDK
        • Open API
          • 频道创建API
          • 修改频道
          • 频道删除API
        • Game Chat资源管理
        • Game Chat版本注释
    • Game Chat (V3)
      • Game Chat(한국어)
        • V3 사용 시작
          • Unity SDK 설치
          • 초기화
          • 로그인
          • 채널
          • 메시지
          • 이벤트
          • 친구
          • 푸시
          • 가져오기&내보내기
          • 고정 메시지
          • 외부연동
          • 사용예제
          • Troubleshooting
      • Game Chat(English)
        • Start using V3
          • Install Unity SDK
          • Initialization
          • Login
          • Channel
          • messages
          • Events
          • Friendship
          • Push
          • Import and export
          • Pinned message
          • External integration
          • Usage examples
          • Troubleshooting
      • Game Chat(日本語)
        • V3の使用を開始
          • Unity SDK のインストール
          • 初期化
          • ログイン
          • チャンネル
          • メッセージ
          • イベント
          • 友達
          • プッシュ
          • インポート&エクスポート
          • 固定メッセージ
          • 外部連携
          • ユースケース
          • Troubleshooting
      • Game Chat(中文)
        • 开始使用V3
          • Unity SDK 安装
          • 初始化
          • 登录
          • 频道
          • 消息功能
          • 事件
          • 好友
          • 推送
          • 导入与导出
          • 固定消息
          • 外部集成
          • 使用示例
          • Troubleshooting
Powered by GitBook
On this page
  • Push
  • Main functions of push notifications
  • Implementation methods of push notifications
  • Security and personal information protection
  • Android(Kotlin)
  • Android (Kotlin) Push Click Event
  • Android (Java)
  • Android (Java) Push Click Event
  • iOS (Swift) Push Click Event
  1. Basics
  2. Game Chat (V3)
  3. Game Chat(English)
  4. Start using V3

Push

Push

In Game 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 Game 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, Game Chat API provides a few core components:

  • Register push tokens: you can register a push token of your device to the Game 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 Game 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: Game Chat takes users' personal information protection very seriously, and provides notification services in accordance with related laws and regulations.

Through the push notifications function, Game 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)

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

Requesting push notification permission popup.

import com.nbase.sdk.Permission

NChat.setEnablePush(true)
NChat.requestPermission(this, Permission.NOTIFICATION)
// It must be called before initialize.

Call setPushState to configure push notification receipt status after connecting.

NChat.setPushState(PushState([PUSH], [AD], [NIGHT])) { state, e ->
    if (e != null) {
        // Error
    } else {
        // Success
    }
}
ID
Type
Description

push

boolean

Push Notification On/Off (true = On)

ad

boolean

Must be called with true for receiving push notifications

night

boolean

Nighttime Push Notification On/ Off

Android (Kotlin) Push Click Event

You can set up an Android push click handler.

NChat.setNotificationClickedHandler { notification ->
    val title = notification.title
    val content = notification.body
    val channel = notification.data?.get("channel") ?: ""
    val imageUrl = notification.data?.get("imageUrl") ?: ""
    val url = notification.data?.get("url") ?: ""
    val metadata = notification.data?.get("metadata") ?: ""
    
    // Define the desired action when a push notification is clicked.
}

Android (Java)

  1. Add the following repository in the project's build.gradle.

allprojects {
    repositories {
    	...
        google()
    	// nbase repo
        maven { url "https://repo.nbase.io/repository/nbase-releases" }
	...
    }
}
  1. Add the following content in the build.gradle of the app module.

dependencies {
    ...
    implementation ("io.nbase:nbasesdk:3.0.78")
    implementation ("io.nbase:nbase-adapter-cloudchat:1.0.17")
    implementation ("com.google.firebase:firebase-messaging-ktx:23.2.1")
    ...
}

Android (Java) Push Click Event

You can set up an Android push click handler.

NChat.INSTANCE.setNotificationClickedHandler(notification -> {
    // Define the desired action when a push notification is clicked.
    String title = notification.getTitle();
    String content = notification.getBody();
    String channel = notification.getData() != null ? notification.getData().get("channel") : "";
});

Android Push Data

This is a list of values delivered through the Android push click handler.

Key
Description

Title

The title set in the push message

Body

The content set in the push message

Data.channel

For chat room pushes, the CHANNEL_ID where the push occurred

iOS(Swift)

Add app push notification permissions. Go to the Target's Signing & Capabilities, click the '+' in the top left corner, and select 'Capability > Push Notifications' to add.

Create a new AppDelegate.swift file or define the following content in the existing AppDelegate.swift.

import UIKit
import NChat

class AppDelegate: NSObject, UIApplicationDelegate {
  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Push Notification Permission Request
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
            print("Permission granted: \(granted)")
        }
        
        UNUserNotificationCenter.current().delegate = self
        application.registerForRemoteNotifications()
        
        // Main Window Configuration
        window = UIWindow(frame: UIScreen.main.bounds)
        let initialViewController = UIViewController()
        initialViewController.view.backgroundColor = .white
        window?.rootViewController = initialViewController
        window?.makeKeyAndVisible()
        
        return true
    }

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        // Convert the device token to a string
        let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
        let token = tokenParts.joined()
        
        // To receive push notifications in the sandbox environment, set sandbox: true.
        NChat.setPushToken(token: token, sandbox: false)
    }
    
    func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
        print("RegisterForRemoteNotifications Failed: \(error.localizedDescription)")
    }
    
        func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        if #available(iOS 14.0, *) {
            completionHandler([.banner, .list, .sound, .badge])
        } else {
            completionHandler([.alert, .sound, .badge])
        }
    }
    
        func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        let userInfo = response.notification.request.content.userInfo

        do {
            try handleNotificationClick(userInfo: userInfo, actionIdentifier: response.actionIdentifier)
        } catch let error as NotificationError {
            print("NotificationError: \(error.localizedDescription)")
        } catch {
            print("UnexpectedError: \(error.localizedDescription)")
        }

        // Call the push notification handling function of the NChat library.
        NChat.handlePushNotification(userInfo: userInfo)
        completionHandler()
    }
}

// Define notification-related errors.
enum NotificationError: LocalizedError {
    case invalidUserInfo(String)
    case navigationError(String)

    var errorDescription: String? {
        switch self {
        case .invalidUserInfo(let message):
            return "잘못된 사용자 정보: \(message)"
        case .navigationError(let message):
            return "네비게이션 오류: \(message)"
        }
    }
}

extension UIViewController {
    func topMostViewController() -> UIViewController {
        if let presented = self.presentedViewController {
            return presented.topMostViewController()
        }
        if let navigation = self as? UINavigationController {
            return navigation.visibleViewController?.topMostViewController() ?? navigation
        }
        if let tab = self as? UITabBarController {
            return tab.selectedViewController?.topMostViewController() ?? tab
        }
        return self
    }
}

Note For push notifications in the sandbox environment, use NChat.setPushToken(token: token, sandbox: true) The sandbox value must be set to true for notifications to be received correctly.

Call setPushState to configure the push notification receipt status after connecting.

NChat.setPushState(push: true, ad: true, night: true) { result in
    switch(result)
    {
    case .success(let status) :
        // Success
        break;
    case .failure(let error) :
        // Failure
        break;
    }
}
ID
Type
Description

push

boolean

Push Notification On/ Off (true = On)

ad

boolean

Must be called with true for receiving push notifications

night

boolean

Nighttime Push Notification On/Offff

iOS (Swift) Push Click Event

You can set up an iOS push click handler. Define it in AppDelegate.swift as shown in the example below.

class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
    var window: UIWindow?
    // Notification Click Handling Function
    private func handleNotificationClick(userInfo: [AnyHashable: Any], actionIdentifier: String) throws {
        if actionIdentifier == UNNotificationDefaultActionIdentifier {
            showNotificationPopup(with: userInfo)
        } else {
            handleCustomAction(actionIdentifier, userInfo: userInfo)
        }
    }

    // Custom Action Handling Function
    private func handleCustomAction(_ actionIdentifier: String, userInfo: [AnyHashable: Any]) {
        switch actionIdentifier {
        case "ACTION_1":
            showNotificationPopup(with: userInfo, title: "ACTION_1")
        case "ACTION_2":
            showNotificationPopup(with: userInfo, title: "ACTION_2")
        default:
            print("actionIdentifier: \(actionIdentifier)")
        }
    }

    // Function to Display Notification Popup
    private func showNotificationPopup(with userInfo: [AnyHashable: Any], title: String = "알림") {
        DispatchQueue.main.async {
            let alertController = UIAlertController(title: title, message: "알림 수신됨", preferredStyle: .alert)

            // Add the contents of userInfo to the message
            for (key, value) in userInfo {
                alertController.message?.append("\n\(key): \(value)")
            }

            let okAction = UIAlertAction(title: "확인", style: .default, handler: nil)
            alertController.addAction(okAction)

            // Find the key window to display the popup
            if let keyWindow = UIApplication.shared.windows.first(where: { $0.isKeyWindow }) {
                if let topViewController = keyWindow.rootViewController?.topMostViewController() {
                    topViewController.present(alertController, animated: true, completion: nil)
                }
            } else {
                print("Unable to find the key window")
            }
        }
    }
}

iOS Push Data

This is a list of values delivered through the iOS push click handler.

Key
Description

Title

The title set in the push message

Body

The content set in the push message

channel

For chat room pushes, the CHANNEL_ID where the push occurred

PreviousFriendshipNextImport and export

Last updated 6 months ago

After adding the Android app in the , download the google-services.json file and place it in the root folder of your project app module. After adding the file, include the following content in bundle.gradle.kts.

Firebase Console