Klat
  • Klat SDK
  • Android
    • Getting Started
    • Callback
    • User
      • 사용자 생성 / 로그인
      • 사용자 정보 업데이트
      • 사용자 차단 목록 관리
      • 사용자 로그아웃
      • 사용자 삭제
    • Channel
      • 채널 생성 / 삭제
      • 채널 조회
      • 채널 정보 업데이트
      • 채널 목록 조회
      • 채널 사용자 관리
      • 채널 참여 / 나가기
      • 채널 내 메시징
      • 채널 숨기기 / 보이기
      • 채널 Freeze / Unfreeze
      • 채널 주인 변경
      • 채널 푸시알림 설정
      • 채널별 개인 데이터 설정
    • Push Notification
    • Sample Application
    • What's New
  • iOS
    • Getting Started
    • Callback
    • User
      • 사용자 생성 / 로그인
      • 사용자 정보 업데이트
      • 사용자 차단 목록 관리
      • 사용자 로그아웃
      • 사용자 삭제
    • Channel
      • 채널 생성 / 삭제
      • 채널 조회
      • 채널 정보 업데이트
      • 채널 목록 조회
      • 채널 사용자 관리
      • 채널 참여 / 나가기
      • 채널 내 메시징
      • 채널 숨기기 / 보이기
      • 채널 Freeze / Unfreeze
      • 채널 주인 변경
      • 채널 푸시알림 설정
      • 채널별 개인 데이터 설정
    • Push Notification
    • Sample Application
    • What's New
  • Unity
    • Getting Started
    • Callback
    • User
      • 사용자 생성 / 로그인
      • 사용자 정보 업데이트
      • 사용자 차단 목록 관리
      • 사용자 로그아웃
      • 사용자 삭제
    • Channel
      • 채널 생성 / 삭제
      • 채널 조회
      • 채널 정보 업데이트
      • 채널 목록 조회
      • 채널 사용자 관리
      • 채널 참여 / 나가기
      • 채널 내 메시징
      • 채널 숨기기 / 보이기
      • 채널 Freeze / Unfreeze
      • 채널 주인 변경
      • 채널 푸시알림 설정
      • 채널별 개인 데이터 설정
    • Push Notification
    • Sample Application
  • JavaScript
    • Getting Started
    • Realtime Event
    • Pagination
    • User
      • 사용자 생성 / 로그인
      • 사용자 정보 업데이트
      • 사용자 차단 목록 관리
      • 사용자 로그아웃
      • 사용자 삭제
    • Channel
      • 채널 생성 / 삭제
      • 채널 조회
      • 채널 정보 업데이트
      • 채널 목록 조회
      • 채널 사용자 관리
      • 채널 참여 / 나가기
      • 채널 내 메시징
      • 채널 숨기기 / 보이기
      • 채널 Freeze / Unfreeze
      • 채널 주인 변경
      • 채널 푸시알림 설정
      • 채널별 개인 데이터 설정
    • Push Notification (FCM)
    • Sample Application
    • What's New
  • Flutter
    • Getting Started
    • Callback
    • User
      • 사용자 생성 / 로그인
      • 사용자 정보 업데이트
      • 사용자 차단 목록 관리
      • 사용자 로그아웃
      • 사용자 삭제
    • Channel
      • 채널 생성 / 삭제
      • 채널 조회
      • 채널 정보 업데이트
      • 채널 목록 조회
      • 채널 사용자 관리
      • 채널 참여 / 나가기
      • 채널 내 메시징
      • 채널 숨기기 / 보이기
      • 채널 Freeze / Unfreeze
      • 채널 주인 변경
      • 채널 푸시알림 설정
      • 채널별 개인 데이터 설정
    • Push Notification
  • REST API
    • Getting Started
    • API
      • User
        • 사용자 생성
        • 사용자 로그인 (로그인 토큰)
        • 사용자 조회
        • 사용자 정보 업데이트
        • 사용자 활성화 / 비활성화
        • 사용자 푸시 알림 설정
        • 사용자 삭제
        • 사용자 목록 조회
        • 사용자 채널 조회
        • 사용자 차단 목록 관리
      • Channel
        • 채널 생성
        • 채널 조회
        • 채널 정보 업데이트
        • 채널 삭제
        • 채널 목록 조회
        • 채널 사용자 관리
        • 채널 내 메시징
        • 채널 숨기기 / 보이기
        • 채널 Freeze / Unfreeze
        • 채널 주인 변경
        • 채널 알림 설정
      • App
        • 앱 조회
        • 앱 생성
        • 앱 삭제
      • Bot
        • 봇 생성
        • 봇 목록 조회
        • 봇 조회
        • 봇 정보 업데이트
        • 봇 삭제
        • 봇 채널 목록 조회
        • 봇 채널 내 메시징
        • 봇 채널 참여 / 나가기
    • Push Notification
    • Rate Limit
  • MISC
    • Webhooks
    • SDK Rate Limit
    • Error Code
    • FAQ
      • Function
      • Spec
Powered by GitBook
On this page
  • Enable / Disable Push Notification
  • Push Notification
  1. iOS

Push Notification

Enable / Disable Push Notification

사용자가 Push Notification을 받을 지 여부를 설정할 수 있습니다.

// 사용자 Push Notification 활성화
[[TalkPlus sharedInstance] enablePushNotification:^(TPUser *tpUser) {
    // SUCCESS
} failure:^(int errorCode, NSError *error) {
    // FAILURE    
}];

// 사용자 Push Notification 비활성화
[[TalkPlus sharedInstance] disablePushNotification:^(TPUser *tpUser) {
    // SUCCESS
} failure:^(int errorCode, NSError *error) {
    // FAILURE    
}];
// 사용자 Push Notification 활성화
TalkPlus.sharedInstance().enablePushNotification { tpUser in
    // SUCCESS
} failure: { (errorCode, error) in }
    // FAILURE    
}

// 사용자 Push Notification 비활성화
TalkPlus.sharedInstance().disablePushNotification { tpUser in
    // SUCCESS
} failure: { (errorCode, error) in }
    // FAILURE    
}

특정 채널의 Push Notification을 받을 지 여부를 설정할 수 있습니다.

// 채널 Push Notification 활성화
[[TalkPlus sharedInstance] enableChannelPushNotification:channel 
    success:^(TPChannel *tpChannel) {
    // SUCCESS
} failure:^(int errorCode, NSError *error) {
    // FAILURE    
}];

// 채널 Push Notification 비활성화
[[TalkPlus sharedInstance] disableChannelPushNotification:channel 
    success:^(TPChannel *tpChannel) {
    // SUCCESS    
} failure:^(int errorCode, NSError *error) {
    // FAILURE
}];
// 채널 Push Notification 활성화
TalkPlus.sharedInstance().enableChannelPushNotification(channel) { channel in
    // SUCCESS
} failure: { (errorCode, error) in 
    // FAILURE  
}

// 채널 Push Notification 비활성화
TalkPlus.sharedInstance().disableChannelPushNotification(channel) { channel in
    // SUCCESS
} failure: { (errorCode, error) in
    // FAILURE  
}

Push Notification

Klat의 Push Notification은 FCM을 통하여 이루어지게 됩니다. 기본적인 FCM을 연동하신 후, User를 로그인한 후 registerFCMToken 함수를 호출하여 FCM 토큰을 User 세션에 연동하여야 합니다.

로그인이 완료된 후 아래와 같이 FIRMessaging을 통하여 token을 얻어 register 하시는 것을 권장 드립니다.

#import <UserNotifications/UserNotifications.h>
@import Firebase;

// 파이어베이스 초기화
[FIRApp configure];
    
// 푸시 권한 요청
UNUserNotificationCenter *center = 
    [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge)
    completionHandler:^(BOOL granted, NSError *error) {
    NSLog(@"granted: %@", granted ? @"YES":@"NO");
}];

// Firebase Messaging을 통하여 현재 token을 획득
[[FIRMessaging messaging] tokenWithCompletion:^(NSString * _Nullable token, NSError * _Nullable error) {
    if (error != nil) {
        NSLog(@"Error getting FCM registration token: %@", error);
    } else {
        NSLog(@"FCM registration token: %@", token);
        [self registerFCMToken:token];
    }
}];

-(void)registerFCMToken:(NSString *)fcmToken {
    [[TalkPlus sharedInstance] registerFCMToken:fcmToken success:^{
        NSLog(@"fcmToken register success");
    } failure:^(int errorCode, NSError *error) {
        NSLog(@"fcmToken register failure");
    }];
}
import Firebase
import FirebaseMessaging
import TalkPlus

// 파이어베이스 초기화
FirebaseApp.configure()

// 푸시 권한 요청
let center = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in
    print(granted)
}
application.registerForRemoteNotifications()

Messaging.messaging().token { [weak self] token, error in
    guard let token = token else { return }
    if(error != nil) {
        print("Error getting FCM registration token: \(String(describing: error))")
        return
    }
    print("FCM registration token: \(token)");
    self?.registerFCMToken(fcmToken: token)
}

func registerFCMToken(fcmToken:String){
    TalkPlus.sharedInstance().registerFCMToken(fcmToken) {
        print("fcmToken register success")
    } failure: { errorCode, error in
        print("fcmToken register failure")
    }
}

그 후 Push Notification이 도착할 경우 아래와 같이 Klat에서 handleFCMMessage 함수를 통하여 payload를 처리하여 기존 등록된 delegate로 이벤트를 전달 드립니다.

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
    willPresentNotification:(UNNotification *)notification
    withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
    // foreground 상태에서 push가 실행될 때 수신
    NSDictionary *userInfo = notification.request.content.userInfo;
    if ([userInfo objectForKey:@"talkplus"] != nil) {
        NSLog(@"talkplus payload");
        [[TalkPlus sharedInstance] handleFCMMessage:[userInfo objectForKey:@"talkplus"]];
    }
    if (@available(iOS 14, *)) {
        completionHandler(UNNotificationPresentationOptionBadge|
                          UNNotificationPresentationOptionSound|
                          UNNotificationPresentationOptionBanner);
    } else {
        completionHandler(UNNotificationPresentationOptionBadge|
                          UNNotificationPresentationOptionSound);
    }
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
    didReceiveNotificationResponse:(UNNotificationResponse *)response
    withCompletionHandler:(void (^)(void))completionHandler
{
    // background 상태에서  push를 클릭했을 때 호출
    NSDictionary *userInfo = response.notification.request.content.userInfo;
    if ([userInfo objectForKey:@"talkplus"] != nil) {
        // 웹 소켓 연결을 통해서 처리
        NSLog(@"talkplus payload found, but do nothing");
    }
}
func userNotificationCenter(_ center: UNUserNotificationCenter,
    willPresent notification: UNNotification,
    withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
{
    // foreground 상태에서 push가 실행될 때 수신
    let userInfo = notification.request.content.userInfo
    if let payload = userInfo["talkplus"] as? String {
        print("talkplus payload")
        TalkPlus.sharedInstance().handleFCMMessage(payload)
    }
    if #available(iOS 14.0, *) {
        completionHandler([.sound, .badge, .banner])
    } else {
        // Fallback on earlier versions
        completionHandler([.sound, .badge])
    }
}

func userNotificationCenter(_ center: UNUserNotificationCenter,
    didReceive response: UNNotificationResponse,
    withCompletionHandler completionHandler: @escaping () -> Void) 
{
    // background 상태에서  push를 클릭했을 때 호출
    let userInfo = response.notification.request.content.userInfo
    if let _ = userInfo["talkplus"] as? String {
        // 웹 소켓 연결을 통해서 처리
        print("talkplus payload found, but do nothing")
    }
}
Previous채널별 개인 데이터 설정NextSample Application

Last updated 3 months ago