ConnectyCube / connectycube-flutter-samples

Code samples for Flutter, based on ConnectyCube platform
https://developers.connectycube.com/flutter/
Apache License 2.0
85 stars 91 forks source link

Pls,Support push notification for event call when Application is close / on background. #8

Closed nguyenquyettienktmt closed 3 years ago

nguyenquyettienktmt commented 4 years ago

I hope that, connectycube-flutter lib, will be support call method when application on close or background for Android and IOS.

Significantinfotech2020 commented 3 years ago

@TatankaConCube

How can I get title and body parameter in onMessage() method while sending push_notification which I get null.

onMessage: {notification: {title: null, body: null}, data: {custom_parameter1: FLUTTER_NOTIFICATION_CLICK, custom_parameter2: custom parameter value 2, message: greyj}}

Please give me suggestion asap.

@TatankaConCube

Please give solution of above question. Please reply!!

TatankaConCube commented 3 years ago

As I said before, the Connectycube server sends push notifications with type 'data', so you can add all required information to 'parameters' during the event creation. You can add all the needed data to this parameter.

One question - did I right understand, now you can receive push notifications on the device?

Significantinfotech2020 commented 3 years ago

As I said before, the Connectycube server sends push notifications with type 'data', so you can add all required information to 'parameters' during the event creation. You can add all the needed data to this parameter.

@TatankaConCube

void sendPushNotification() {
    CreateEventParams params = CreateEventParams();
    params.parameters = {
      'message': '${textEditingController.text}',
      'custom_parameter1': 'custom parameter value 1',
      'custom_parameter2': "custom parameter value 2",
      'ios_voip': 1
    };
    params.notificationType = '${NotificationType.PUSH}';
    params.environment = CubeEnvironment.DEVELOPMENT;
    params.usersIds = _cubeDialog.occupantsIds;

    createEvent(params.getEventForRequest()).then((cubeEvent) {
      print('CUBE EVENT -----> $cubeEvent');
    }).catchError((error) {
      print('CUBE EVENT ERROR -----> $error');
    });
  }

One question - did I right understand, now you can receive push notifications on the device?

I can receive notification, if I get onMessage() method in 'data' parameter rather than 'notification'. Sorry, still I did not receive notification on device. But It successfully generated from connectycube dashboard.

onMessage: {notification: {title: null, body: null}, data: {custom_parameter1: FLUTTER_NOTIFICATION_CLICK, custom_parameter2: custom parameter value 2, message: greyj}}

Significantinfotech2020 commented 3 years ago

As I said before, the Connectycube server sends push notifications with type 'data', so you can add all required information to 'parameters' during the event creation. You can add all the needed data to this parameter.

@TatankaConCube In above code snippet where I have to pass type 'data' as you said? Please suggest me.

TatankaConCube commented 3 years ago

it can be like:

params.parameters = {
      'message': '${textEditingController.text}',
      'title': someTitle,
      'body': someBody,
// all needed parameters here 
      'ios_voip': 1
    };
Significantinfotech2020 commented 3 years ago

it can be like:

params.parameters = {
      'message': '${textEditingController.text}',
      'title': someTitle,
      'body': someBody,
// all needed parameters here 
      'ios_voip': 1
    };

@TatankaConCube

I did exact same as you suggest but still I face that title and parameter null in onMessage() method. What should I do now?

params.parameters = { 'message': '${textEditingController.text}', 'title': 'Chat Notification', 'body': "chat body", 'notification_type': 'push', 'push_type': 'gcm', 'environment': 'development', 'ios_voip': 1, 'usersIds' = ${_cubeDialog.occupantsIds} };

TatankaConCube commented 3 years ago

in the 'data' field? are you sure? please provide log, like you did before. I mean it:

onMessage: {notification: {title: null, body: null}, data: {custom_parameter1: FLUTTER_NOTIFICATION_CLICK, custom_parameter2: custom parameter value 2, message: greyj}}

Significantinfotech2020 commented 3 years ago

@TatankaConCube

in the 'data' field? are you sure?

Yes.

please provide log, like you did before. I mean it:

onMessage, message: {notification: {title: null, body: null}, data: {notification_type: push, push_type: gcm, environment: development, body: c
hat body, title: Chat Notification, message: gfghgg}}
TatankaConCube commented 3 years ago

what about it:

data: {notification_type: push, push_type: gcm, environment: development, body: chat body, title: Chat Notification, message: gfghgg}

why you say

title and parameter null in onMessage()

I'm confused...

Significantinfotech2020 commented 3 years ago

what about it:

data: {notification_type: push, push_type: gcm, environment: development, body: chat body, title: Chat Notification, message: gfghgg}

why you say

title and parameter null in onMessage()

I'm confused...

sorry for this. but still I didn't receive notification.

TatankaConCube commented 3 years ago

do you mean notification in the Android notifications center? For the Android platform, you should do it by yourself, please read our documentation (at the end of the section). For iOS, it is a system feature and here you can manage only actions, which happen by clicking on the notification.

Significantinfotech2020 commented 3 years ago

@shivanijha002

Notification: title and body should not be null. How can I set these values?

For the Android platform, you have to set them to the parameters map, for iOS you can use some additional parameter from our API. Note: ConnectyCube server always sends GCM with 'data' type, not 'notification'.

Also, I do not get any notification on device. Though message is getting captured in debug console.

For Android, it is expected behavior. You have to do it yourself. For example, you can use flutter_local_notifications plugin for it. For iOS, it is a system feature and the system does it instead of you.

Thank you for the details. It might be useful if you can add it in your documentation. I wasted 2 days trying out different things and hoping it will work without anything external. flutter_local_notifications has worked for me on Android.

Hello @shivanijha002

I face same issue as you mentioned above. Please suggest me how can I use flutter_local_notifications with firebase_messaging for Android device notification. Please suggest me asap.

TatankaConCube commented 3 years ago

@Significantinfotech2020 in your callback onMessage you have all the needed data, please read documentation how to configure notification with this data and how to show it.

Significantinfotech2020 commented 3 years ago

Hello @TatankaConCube,

I share my chat_dialog_screen.dart file. In this file I implemented flutter_local_notifications with firebase_messaging, but still I can't get any notification on receiver device. In this code I got notification on sender device with only notification title. So, please check my code and let me know where I made mistake? What changes I have to do in this code?

TatankaConCube commented 3 years ago

There are few plugins for listening push notifications and a lot of code is commented. Do you receive a push event in your callbacks? We are going to plan to add a push notification feature for the Chat sample in the next iteration.

TatankaConCube commented 3 years ago

@Significantinfotech2020 today I pushed draft code for enabling push notifications in the Chat sample. The main logic for subscription, listening push notifications and showing local notifications placed in push_notifications_manager.dart

At current moment works (tested on iOS and Android):

Note: it is just a draft and not all features implemented yet, for example, navigation to concrete chat by notification click, etc.

Significantinfotech2020 commented 3 years ago

@Significantinfotech2020 today I pushed draft code for enabling push notifications in the Chat sample. The main logic for subscription, listening push notifications and showing local notifications placed in push_notifications_manager.dart

At current moment works (tested on iOS and Android):

  • subscription on push notifications;
  • receiving push notifications in the background (or killed) and foreground;
  • displaying notifications in Notification Center;
  • unsubscription from push notifications after logout from the app;

Note: it is just a draft and not all features implemented yet, for example, navigation to concrete chat by notification click, etc.

@TatankaConCube I checked this code. It's working as you describe. Thanks 👍

Significantinfotech2020 commented 3 years ago

Hello @TatankaConCube In your code sometimes I got notification but sometimes not. I had updated code as per latest documentation. There was not any error in the terminal.

TatankaConCube commented 3 years ago

In which way do you send push notification? From admin panel?

Significantinfotech2020 commented 3 years ago

@TatankaConCube

In which way do you send push notification?

I am sending notification as per your updated code.

From admin panel?

No.

TatankaConCube commented 3 years ago

Did these notifications present in the queue in the Admin panel?

Significantinfotech2020 commented 3 years ago

Did these notifications present in the queue in the Admin panel?

when I receive notification on device that entries were in admin panel, but when I not get notification, that entry was not in queue.

TatankaConCube commented 3 years ago

it means you have a problem not with receiving but with sending notifications, investigate this part of your code

Significantinfotech2020 commented 3 years ago

@TatankaConCube In below method 6543 is what? Is this application ID or Account ID or anything else?

FlutterLocalNotificationsPlugin().show(
    6543, 
    "Chat sample",
    data['message'].toString(),
    platformChannelSpecifics,
    payload: 'item x',
  );
TatankaConCube commented 3 years ago

There is code not from our SDK, it is a code of flutter_local_notifications plugin. There is the description for this code example. In my example, 6543 is just a random notification id. Notification id - for the Android system it is the unique id of your notification, by this id you can cancel notification, update it, etc.

TatankaConCube commented 3 years ago

Implemented in the latest version. Closing...