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. Flutter

Push Notification

Enable / Disable Push Notification

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

// Enable push notification
await TalkPlusAPI.enablePushNotification(errorCallback: (errorCode, errorMessage){

});

// Disable push notification
await TalkPlusAPI.disablePushNotification(errorCallback: (errorCode, errorMessage){

});

Push Notification

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

await TalkPlusAPI.registerFCMToken(
    fcmToken,
    errorCallback: (errorCode, errorMessage){}
);

이후 아래와 같이 TalkPlus에서 제공하는 processFirebaseCloudMessagingData 함수를 호출하는 코드를 삽입하여 Push Notification을 처리할 수 있습니다.

Foreground인 경우 기존에 등록되어있는 ChannelListener를 통하여 자동으로 콜백을 올리게 됩니다.

Background인 경우 앱이 실행되어있지 않은 상태라 등록된 콜백이 없을 수 있으므로 아래와 같이 1회용 콜백을 함께 등록하여 이벤트를 받아 원하는 동작을 수행하실 수 있습니다.

processFirebaseCloudMessagingData 함수에서 마지막 인자값으로 forceCallback을 boolean 으로 받게 되어 있는데, forceCallback은 실시간 채널에서 콜백 수신과 상관없이 FCM 통해 무조건 콜백을 받아 처리하기 위해서는 true로 넘겨주셔야 합니다.

class Application extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _Application();
}

class _Application extends State<Application> {
  // It is assumed that all messages contain a data field with the key 'type'
  Future<void> setupInteractedMessage() async {
    // Get any messages which caused the application to open from
    // a terminated state.
    RemoteMessage? initialMessage =
        await FirebaseMessaging.instance.getInitialMessage();

    // If the message also contains a data property with a "type" of "chat",
    // navigate to a chat screen
    if (initialMessage != null) {
      _handleMessage(initialMessage);
    }

    // Also handle any interaction when the app is in the background via a
    // Stream listener
    FirebaseMessaging.onMessageOpenedApp.listen(_handleMessage);
  }
  
  void _handleMessage(RemoteMessage message) {
    if (message.data.containsKey("talkplus")) {
        // channelId, title, body 정보가 필요한 경우 아래와 같이 사용합니다.
        // var msg = convert.jsonDecode(message.data['talkplus'])
        // String channelId = talkplus.getString("channelId");
        // String messageId = talkplus.getString("messageId"); // available only for message event
        // String title = talkplus.getString("title");
        // String body = talkplus.getString("body");
        
        await TalkPlusAPI.processFirebaseCloudMessagingData(message.data, onetimeListener, forceCallback);
    }
  }

  @override
  void initState() {
    super.initState();

    // Run code required to handle interacted messages in an async function
    // as initState() must not be async
    setupInteractedMessage();
  }

  @override
  Widget build(BuildContext context) {
    return Text("...");
  }
}

포그라운드와 백그라운드 모두 동일하게 onMessageReceived를 통해 개발자가 원하는대로 컨트롤 하려면 Data타입의 푸쉬를 받아야 합니다. 대시보드에 다음과 같이 설정해야 data 타입 푸쉬를 받게 되십니다:

  • 전체 Push Notification 설정 활성화

  • AOS "메시지 수신 알림" 비활성화

Previous채널별 개인 데이터 설정NextGetting Started

Last updated 1 year ago