Klat
  • TalkPlus SDK
  • Android
    • Getting Started
    • Callback
    • User
      • Create User / Login
      • Update User Information
      • Block / Unblock
      • Logout
      • Delete User
    • Channel
      • Create / Delete Channel
      • View Channel
      • Updating Channel
      • Viewing Channel LIst
      • Manage Channel Members
      • Join / Leave Channel
      • Messaging
      • Hide / Show Channel
      • Freeze / Unfreeze Channel
      • Transfer Channel Ownership
      • Channel Push Notification Settings
      • Channel Member Data
    • Push Notification
    • Sample Application
    • What's New
  • iOS
    • Getting Started
    • Callback
    • User
      • Create / Login
      • Update User Information
      • Block / Unblock
      • Logout
      • Delete User
    • Channel
      • Create / Delete Channel
      • View Channel
      • Updating Channel
      • View Channel List
      • Manage Channel Members
      • Join / Leave Channel
      • Messaging
      • Hide / Show Channel
      • Freeze / Unfreeze Channel
      • Transfer Channel Ownership
      • Channel Push Notification Settings
      • Channel Member Data
    • Push Notification
    • Sample Application
    • What's New
  • Unity
    • Getting Started
    • Callback
    • User
      • Create User / Login
      • Update User Information
      • Block / Unblock
      • Logout
      • Delete User
    • Channel
      • Create / Delete Channel
      • View Channel
      • Updating Channel
      • View Channel List
      • Manage Channel Members
      • Join / Leave Channel
      • Messaging
      • Hide / Show Channel
      • Freeze / Unfreeze Channel
      • Transfer Channel Ownership
      • Channel Push Notification Settings
      • Channel Member Data
    • Push Notification
    • Sample Application
  • JavaScript
    • Getting Started
    • Realtime Event
    • Pagination
    • User
      • Create User / Login
      • Update User Information
      • Block / Unblock
      • Logout
      • Delete
    • Channel
      • Create / Delete Channel
      • View Channel
      • Updating Channel
      • View Channel List
      • Manage Channel Members
      • Join / Leave Channel
      • Messaging
      • Hide / Show Channel
      • Freeze / Unfreeze Channel
      • Transfer Channel Ownership
      • Channel Push Notification Settings
      • Channel Member Data
    • Push Notification (FCM)
    • Sample Application
    • What's New
  • Flutter
    • Getting Started
    • Callback
    • User
      • Create User / Login
      • Update User Information
      • Block / Unblock
      • Logout
      • Delete User
    • Channel
      • Create Channel
      • View Channel
      • Updating Channel
      • View Channel List
      • Manage Channel Members
      • Join / Leave Channel
      • Messaging
      • Hide / Show Channel
      • Freeze / Unfreeze Channel
      • Transfer Channel Ownership
      • Channel Push Notification Settings
      • Channel Member Data
    • Push Notification (FCM)
  • REST API
    • Getting Started
    • API
      • Users
        • Create User
        • Login (using login token)
        • View User
        • Update User
        • Activate / Deactivate
        • Enable / Disable Push Notification
        • Delete User
        • View Users
        • View Channels
        • Block / Unblock
      • Channel
        • Create Channel
        • View Channel
        • Update Channel
        • Delete Channel
        • View Channel List
        • Manage Channel Members
        • Messaging
        • Hide / Show Channel
        • Channel Freeze / Unfreeze
        • Transfer Channel Ownership
        • Channel Push Notification Settings
      • Bot
        • Create Bot
        • View Bot List
        • View Bot
        • Update Bot
        • Delete Bot
        • View Joined Channel List
        • Messaging
        • Join / Leave Channel
    • 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 (FCM)

Enable / Disable Push Notification

You can set whether users receive push notifications.

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

});

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

});

Push Notification

Push Notification is handled by FCM.

First, integrate FCM on TalkPlus dashboard. Then, when a user logs in, call registerFCMToken function to register FCM token from that device.

The following code demonstrates how you can obtain and register an FCM token.

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

You can then call processFirebaseCloudMessagingData function to handle push notifications, as shown below.

When app is running in the foreground, callback is automatically handled by an already registered ChannelListener. When app is in the background, app is currently not running and may not have a callback already registered. In that case, you can register an anonymous callback to handle events as shown below:

(processFirebaseCloudMessagingData function accepts boolean value for its last parameter forceCallback. You must set forceCallback to true to receive callbacks from FCM, regardless of whether you are already receiving callbacks from the realtime connection.)

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("...");
  }
}

In order to have complete control of FCM push notification both in foreground and background, you need to receive FCM data type push notification and handle it via onMessageReceived. To enable this feature, you need to make sure the following settings are in place in dashboard:

  • Enable push notification

  • Disable push notification for Android (this allows only data type FCM notifications for Android)

PreviousChannel Member DataNextGetting Started

Last updated 11 months ago