Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nguyenquyettienktmt opened this issue Jun 28, 2020 · 76 comments

Comments

@nguyenquyettienktmt
Copy link

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

@TatankaConCube
Copy link
Contributor

Yes, we plan to add background calls support in one of near release.

@nguyenquyettienktmt
Copy link
Author

Yeahhhh, I love U 3000 <3

@StanevPrime
Copy link

+1 for this awesome feature as this is essential for each VoiP App :)

@najibghadri
Copy link

najibghadri commented Jul 6, 2020

Is there a way to implement this with the current API? In a background process for example with the workmanager plugin perhaps?

@TatankaConCube
Copy link
Contributor

hello guys, we updated our Push Notifications documentation for Flutter. You can try use it to implement Push notifications to your Flutter projects before we implement it in our sample.

@shivanijha002
Copy link

I am trying to use Push notification for Android however, it is not working as expected.
code sample:
image

Result:
image
image
image

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

Also, I do not get any notification on device. Though message is getting captured in debug console.
If I send dummy message from FCM console, my device do get alert but not from Connectycube 'Push Notifications'-> 'Send' console.

@TatankaConCube
Copy link
Contributor

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

@shivanijha002
Copy link

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

@Significantinfotech2020

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

@shivanijha002

Please, give me suggestion how to get notification using flutter_local_notifications for Push notification.

I got below error:

 Invalid argument(s): Failed to setup background message handler! `onBackgroundMessage`
 should be a TOP-LEVEL OR STATIC FUNCTION and should NOT be tied to a
 class or an anonymous function.

@Significantinfotech2020
Copy link

Significantinfotech2020 commented Oct 22, 2020

Hello @TatankaConCube

  • How to get pushToken in subscription for push notification?

parameters.pushToken = "2b6f0cc9...4b831186";

  • push token is static or dynamic?

  • deviceId is static or dynamic and also how can I get It?

I get device id is this way using device_info: ^0.4.2+9 package and below method.

Future<String> _getId() async {
    var deviceInfo = DeviceInfoPlugin();
    if (Platform.isIOS) {
      // import 'dart:io'
      var iosDeviceInfo = await deviceInfo.iosInfo;
      return iosDeviceInfo.identifierForVendor; // unique ID on iOS
    } else {
      var androidDeviceInfo = await deviceInfo.androidInfo;
      });
      return androidDeviceInfo.androidId; // unique ID on Android
    }
  }

Is this right way or I have to implement other method?

  • When I send notification It registerd on dashboard but it displays in falied status.

So, help me to solve this issue.

@TatankaConCube
Copy link
Contributor

How to get pushToken in subscription for push notification?

you have to use flutter plugins for this, in our documentation, we provided the needed code for this.

push token is static or dynamic?

it can be changed during the app work, please, see our documentation, how to get the current token, and how to subscribe to its changes.

deviceId is static or dynamic and also how can I get It?

it is a static unique identifier for your device on the ConnectyCube server. You provided the correct code for getting it.

When I send notification It registerd on dashboard but it displays in falied status.

need more details about this issue:

  • which error present in failed log?
  • have some receivers subscription in the Connectycube admin panel?
  • for which platform (Android or iOS) do you send notification?
  • how you send notification (via API from app or from Admin panel)?

@Significantinfotech2020
Copy link

Significantinfotech2020 commented Oct 22, 2020

@TatankaConCube
- which error present in failed log?

W/System.err( 4415): java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.ClipData.getItemCount()' on a null object reference
W/System.err( 4415):    at android.os.Parcel.readException(Parcel.java:1626)
W/System.err( 4415):    at android.os.Parcel.readException(Parcel.java:1573)
W/System.err( 4415):    at android.content.IClipboard$Stub$Proxy.getPrimaryClip(IClipboard.java:197)
W/System.err( 4415):    at android.content.ClipboardManager.getPrimaryClip(ClipboardManager.java:247)
W/System.err( 4415):    at io.flutter.plugin.platform.PlatformPlugin.getClipboardData(PlatformPlugin.java:283)
W/System.err( 4415):    at io.flutter.plugin.platform.PlatformPlugin.access$700(PlatformPlugin.java:24)
W/System.err( 4415):    at io.flutter.plugin.platform.PlatformPlugin$1.getClipboardData(PlatformPlugin.java:82)
W/System.err( 4415):    at io.flutter.embedding.engine.systemchannels.PlatformChannel$1.onMethodCall(PlatformChannel.java:141)
W/System.err( 4415):    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
W/System.err( 4415):    at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
W/System.err( 4415):    at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
W/System.err( 4415):    at android.os.MessageQueue.nativePollOnce(Native Method)
W/System.err( 4415):    at android.os.MessageQueue.next(MessageQueue.java:323)
W/System.err( 4415):    at android.os.Looper.loop(Looper.java:143)
W/System.err( 4415):    at android.app.ActivityThread.main(ActivityThread.java:7224)
W/System.err( 4415):    at java.lang.reflect.Method.invoke(Native Method)
W/System.err( 4415):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
W/System.err( 4415):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

Screenshot (9)
Screenshot (10)
Screenshot (11)

Failed notification log :
{"notification":{"id":6382549,"badge":null,"device_token":null,"sound":"default","alert":null,"data":{"message":"jhfgjhbn","custom_parameter1":"FLUTTER_NOTIFICATION_CLICK","custom_parameter2":"custom parameter value 2","collapse_key":"event3072823"},"expiry":86400,"delivered":false,"delivered_at":null,"failed":true,"failed_at":"2020-10-22T09:16:38+00:00","fail_after":"2020-10-22T10:16:32+00:00","retries":0,"error_code":null,"error_description":"Unable to deliver notification 6382549, received error (Failed to deliver to all recipients. Errors: InvalidRegistration.)","deliver_after":null,"alert_is_json":null,"app_id":1246,"collapse_key":null,"delay_while_idle":false,"registration_ids":["2206393...2206393"],"uri":null,"priority":10,"url_args":null,"category":null,"content_available":false,"mutable_content":false,"notification":null,"type":"Rpush::Client::Redis::Gcm::Notification","event_id":3072823,"event_date":"2020-10-22T09:16:31+00:00"},"log":[{"device_token":null,"delivered_at":null,"failed_at":"2020-10-22T09:16:38+00:00","error_code":null,"error_description":"Unable to deliver notification 6382549, received error (Failed to deliver to all recipients. Errors: InvalidRegistration.)"}]}

- have some receivers subscription in the Connectycube admin panel?
Yes.
Screenshot (8)

- for which platform (Android or iOS) do you send notification?
Android

- how you send notification (via API from app or from Admin panel)?
I follow step to integrate notification.

I want to send send using firebase with your dashboard.

@Significantinfotech2020
Copy link

Significantinfotech2020 commented Oct 23, 2020

Hello @TatankaConCube

I want to use notification functionality in chat application. I implemented this functionality using your connectycube_sdk package. I follow each and every steps to do this functionality and also I successfully implemented this functionality. But in this code I face one issue is that when user is offline or not in the dialog page I can't get notification. In terminal there is no any error display. Every API from your server is called successfully and it displays log of generated notification. When I push on send button notification generates which displays in connecty_cube dashboard. Also device is registered in Push Notification -> Device subscription panel. Every notification displays in Push Notification -> Queue panel. but in this panel Start date, End date, Period are not displayed. When I click on status I get this issue in log received error (Failed to deliver to all recipients. Errors: InvalidRegistration). So I can't get receiver for notification. I use android device for notification. I also link my application with firebase, but in firebase console -> cloud messaging there is no any data display for notification. Please help me to solve this issue asap. I also displays image in above comment. Please check it.

this is log.

I/flutter (23928): CB-SDK: : =========================================================
I/flutter (23928): === REQUEST ==== 4950eb17-f364-421a-9a5e-50a8fca32438 ===
I/flutter (23928): REQUEST
I/flutter (23928):   GET https://api.connectycube.com/chat/Dialog/5f897318ca8bf43be78fc7c3/notifications
I/flutter (23928): HEADERS
I/flutter (23928):   {Content-type: application/json, ConnectyCube-REST-API-Version: 0.1.1, CB-SDK: Flutter 0.5.0, CB-Token: 0c329ee573ed050c6cd83255180318651c000d91}
I/flutter (23928): BODY
I/flutter (23928):
I/flutter (23928):
I/flutter (23928): pushToken======2206408...2206393
I/flutter (23928): === REQUEST ==== ebf91f59-d7b9-4c9f-a7c5-3cb3f128537e ===
I/flutter (23928): REQUEST
I/flutter (23928):   POST https://api.connectycube.com/subscriptions
I/flutter (23928): HEADERS
I/flutter (23928):   {Content-type: application/json, ConnectyCube-REST-API-Version: 0.1.1, CB-SDK: Flutter 0.5.0, CB-Token: 0c329ee573ed050c6cd83255180318651c000d91}
I/flutter (23928): BODY
I/flutter (23928):   {"notification_channel":"gcm","device":{"udid":"e1f422d058f5ec16","platform":"android"},"push_token":{"environment":"development","client_identificatio
n_sequence":"2206408...2206393"}}
I/flutter (23928):
I/flutter (23928): CB-SDK: : {parameters: {message: jhfgjhbn, custom_parameter1: FLUTTER_NOTIFICATION_CLICK, custom_parameter2: custom parameter value 2, ios_voip: 1}, noti
ficationType: push, environment: development, eventType: null, usersIds: [2206393, 2206408], externalUsersIds: [], usersTagsAll: [], usersTagsAny: [], usersTagsExclude: [],
 date: null, endDate: null, period: null, name: null}
I/flutter (23928): CB-SDK: : =========================================================
I/flutter (23928): === REQUEST ==== 8a349d32-3840-4564-806a-e672bd7c3a5f ===
I/flutter (23928): REQUEST
I/flutter (23928):   POST https://api.connectycube.com/events
I/flutter (23928): HEADERS
I/flutter (23928):   {Content-type: application/json, ConnectyCube-REST-API-Version: 0.1.1, CB-SDK: Flutter 0.5.0, CB-Token: 0c329ee573ed050c6cd83255180318651c000d91}
I/flutter (23928): BODY
I/flutter (23928):   {"event":{"notification_type":"push","environment":"development","message":"eyJtZXNzYWdlIjoiamhmZ2poYm4iLCJjdXN0b21fcGFyYW1ldGVyMSI6IkZMVVRURVJfTk9USUZ
JQ0FUSU9OX0NMSUNLIiwiY3VzdG9tX3BhcmFtZXRlcjIiOiJjdXN0b20gcGFyYW1ldGVyIHZhbHVlIDIiLCJpb3Nfdm9pcCI6MX0=","user":{"ids":"2206393,2206408"}}}
I/flutter (23928):
I/flutter (23928): CB-SDK: : onSendMessage message= {_id: 5f92a61cd8755caca57ed8a0, chat_dialog_id: null, message: ytt, date_sent: 1603446300, sender_id: null, recipient_id
: null, read_ids: null, delivered_ids: null, views_count: null, attachments: null, id: null, created_at: null, updated_at: null}
I/flutter (23928): sending: <message id="5f92a61cd8755caca57ed8a0" type="chat" to="2206408-3473@chat.connectycube.com">
I/flutter (23928):   <body>ytt</body>
I/flutter (23928):   <extraParams xmlns="jabber:client">
I/flutter (23928):     <date_sent>1603446300</date_sent>
I/flutter (23928):     <save_to_history>1</save_to_history>
I/flutter (23928):     <dialog_id>5f897318ca8bf43be78fc7c3</dialog_id>
I/flutter (23928):   </extraParams>
I/flutter (23928):   <markable xmlns="urn:xmpp:chat-markers:0"/>
I/flutter (23928): </message>
I/flutter (23928): List Length ======>>>>>> 6
I/flutter (23928): List Length ======>>>>>> 6
I/flutter (23928): markAsReadIfNeed message= {_id: 5f9299a4745a45347ae9af28, chat_dialog_id: 5f897318ca8bf43be78fc7c3, message: hello, date_sent: 1603443108, sender_id: 220
6408, recipient_id: 2206393, read_ids: [2206408, 2206393], delivered_ids: [2206408, 2206393], views_count: 0, attachments: [], id: null, created_at: 2020-10-23 08:51:48.000
Z, updated_at: 2020-10-23 09:44:49.000Z}, isOpponentMsgRead= true
D/InputMethodManager(23928): prepareNavigationBarInfo() DecorView@a03dc7[MainActivity]
D/InputMethodManager(23928): getNavigationBarColor() -855310
V/InputMethodManager(23928): Starting input: tba=com.example.chatconnectycubesdk ic=io.flutter.plugin.editing.InputConnectionAdaptor@d0fd6ee mNaviBarColor -855310 mIsGetNav
iBarColorSuccess true , NavVisible : true , NavTrans : false
D/InputMethodManager(23928): startInputInner - Id : 0
I/InputMethodManager(23928): startInputInner - mService.startInputOrWindowGainedFocus
D/InputTransport(23928): Input channel constructed: fd=110
D/InputTransport(23928): Input channel destroyed: fd=99
W/IInputConnectionWrapper(23928): getExtractedText on inactive InputConnection
I/chatty  (23928): uid=10310(com.example.chatconnectycubesdk) identical 1 line
W/IInputConnectionWrapper(23928): getExtractedText on inactive InputConnection
I/flutter (23928): List Length ======>>>>>> 6
I/flutter (23928): List Length ======>>>>>> 6
I/flutter (23928): List Length ======>>>>>> 6
I/flutter (23928): markAsReadIfNeed message= {_id: 5f927bbc383c35711b8cfe37, chat_dialog_id: 5f897318ca8bf43be78fc7c3, message: hiii, date_sent: 1603435452, sender_id: 2206
408, recipient_id: 2206393, read_ids: [2206408, 2206393], delivered_ids: [2206408, 2206393], views_count: 0, attachments: [], id: null, created_at: 2020-10-23 06:44:13.000Z
, updated_at: 2020-10-23 06:44:19.000Z}, isOpponentMsgRead= true
I/flutter (23928): List Length ======>>>>>> 6
I/flutter (23928): CB-SDK: : *********************************************************
I/flutter (23928): *** RESPONSE *** 201 *** ebf91f59-d7b9-4c9f-a7c5-3cb3f128537e ***
I/flutter (23928): HEADERS
I/flutter (23928):   {connection: keep-alive, cache-control: max-age=0, private, must-revalidate, set-cookie: _mkra_ctxt=a1b03485c8ab6e70df32f38b2d58c279--201; path=/; max-
age=5; HttpOnly; secure, status: 201 Created, transfer-encoding: chunked, date: Fri, 23 Oct 2020 09:44:57 GMT, access-control-allow-origin: *, strict-transport-security: ma
x-age=31536000,max-age=15768000;, content-type: application/json; charset=utf-8, x-xss-protection: 1; mode=block, server: nginx/1.16.1, x-request-id: b210adc3-c7a3-4049-b05
d-1e4d607bdad1, cb-token-expirationdate: 2020-10-23 11:44:27 UTC, connectycube-rest-api-version: 0.1.1, x-runtime: 0.027089, etag: W/"27aa6142f05dbd6d4d2105b5149448e5", x-f
rame-options: SAMEORIGIN, x-content-type-options: nosniff}
I/flutter (23928): BODY
I/flutter (23928):   [{"subscription":{"id":442885,"device":{"udid":"e1f422d058f5ec16","client_identification_sequence":"2206408...2206393","platform":{"name":"android"},"b
undle_identifier":null},"notification_channel":{"name":"gcm"}}}]
I/flutter (23928):
I/flutter (23928): SUBSCRIPTION SUCCESS ====> [{notification_channel: gcm, push_token: null, device: {udid: e1f422d058f5ec16, platform: android}}]
I/flutter (23928): sending: <r xmlns="urn:xmpp:sm:3"/>
I/flutter (23928): CB-SDK: : *********************************************************
I/flutter (23928): *** RESPONSE *** 200 *** 4950eb17-f364-421a-9a5e-50a8fca32438 ***
I/flutter (23928): HEADERS
I/flutter (23928):   {connection: keep-alive, cache-control: max-age=0, private, must-revalidate, set-cookie: _mkra_ctxt=cb3191b803a445004f859dd28cd42e06--200; path=/; max-
age=5; HttpOnly; secure, status: 200 OK, transfer-encoding: chunked, date: Fri, 23 Oct 2020 09:44:57 GMT, access-control-allow-origin: *, strict-transport-security: max-age
=31536000,max-age=15768000;, content-type: application/json; charset=utf-8, x-xss-protection: 1; mode=block, server: nginx/1.16.1, x-request-id: 7639f729-d822-4296-8dc0-41b
7f1362303, cb-token-expirationdate: 2020-10-23 11:44:27 UTC, connectycube-rest-api-version: 0.1.1, x-runtime: 0.020983, etag: W/"f18ac01a1af2e0e9da770f90521f6336", x-frame-
options: SAMEORIGIN, x-content-type-options: nosniff}
I/flutter (23928): BODY
I/flutter (23928):   {"notifications":{"enabled":1}}
I/flutter (23928):
I/flutter (23928): NOTIFICATION ENABLE ==> true
I/flutter (23928): CB-SDK: : *********************************************************
I/flutter (23928): *** RESPONSE *** 201 *** 8a349d32-3840-4564-806a-e672bd7c3a5f ***
I/flutter (23928): HEADERS
I/flutter (23928):   {connection: keep-alive, cache-control: max-age=0, private, must-revalidate, set-cookie: _mkra_ctxt=e6706b5c9bf4f8206601a71b07ff5e42--201; path=/; max-
age=5; HttpOnly; secure, status: 201 Created, transfer-encoding: chunked, date: Fri, 23 Oct 2020 09:44:57 GMT, access-control-allow-origin: *, strict-transport-security: ma
x-age=31536000,max-age=15768000;, content-type: application/json; charset=utf-8, x-xss-protection: 1; mode=block, server: nginx/1.16.1, x-request-id: bd9580bd-bb06-4843-a65
a-bbcbd8680f27, cb-token-expirationdate: 2020-10-23 11:44:27 UTC, connectycube-rest-api-version: 0.1.1, x-runtime: 0.114506, etag: W/"e030cb2767d2eab406427c8910da6753", x-f
rame-options: SAMEORIGIN, x-content-type-options: nosniff}
I/flutter (23928): BODY
I/flutter (23928):   [{"event":{"id":3154266,"event_type":"one_shot","message":"data.message=amhmZ2poYm4=\u0026data.custom_parameter1=RkxVVFRFUl9OT1RJRklDQVRJT05fQ0xJQ0s=\u
0026data.custom_parameter2=Y3VzdG9tK3BhcmFtZXRlcit2YWx1ZSsy","date":null,"period":null,"name":null,"occured_count":0,"created_at":"2020-10-23T09:44:57Z","updated_at":"2020-
10-23T09:44:57Z","end_date":null,"active":true,"application_id":3473,"user_id":2206393,"kind":"ChatAlert","environment":"development","tag_query":null,"notification_channel
":{"name":"gcm"}}}]
I/flutter (23928):
I/flutter (23928): CUBE EVENT -----> [{notification_type: null, environment: development, message: {message: jhfgjhbn, custom_parameter1: FLUTTER_NOTIFICATION_CLICK, custom
_parameter2: custom parameter value 2}, event_type: one_shot}]
I/flutter (23928): response: <a xmlns='urn:xmpp:sm:3' h='9'/>
I/flutter (23928): !!!!handle response <xmpp_stone><a xmlns='urn:xmpp:sm:3' h='9'/></xmpp_stone>
I/flutter (23928): !!!!!!! PARSED<xmpp_stone><a xmlns='urn:xmpp:sm:3' h='9'/></xmpp_stone>
I/flutter (23928): Delivered: NPFMPIMRU
I/flutter (23928): Delivered: UIXNVLBFW
I/flutter (23928): Delivered: LFEEJHOVX
I/flutter (23928): Delivered: 5f92a61cd8755caca57ed8a0

@TatankaConCube
Copy link
Contributor

There are descriptions of possible errors on sending push notifications from Connectycube server to FCM. Looks like you have the wrong (or expired) token in the subscription. Try delete the subscription from the admin panel and create a new one, then try to send push notification again.

@Significantinfotech2020

There are descriptions of possible errors on sending push notifications from Connectycube server to FCM. Looks like you have the wrong (or expired) token in the subscription. Try delete the subscription from the admin panel and create a new one, then try to send push notification again.

Hello @TatankaConCube
Please check log which is updated in above comment.

@TatankaConCube
Copy link
Contributor

And you get the same error again? Right?

@Significantinfotech2020

And you get the same error again? Right?

Yes

@TatankaConCube
Copy link
Contributor

Did you configure the required tokens in the ConnectyCube admin console? Did you add google-services.json file to your Android project?

@Significantinfotech2020

Did you configure the required tokens in the ConnectyCube admin console? Did you add google-services.json file to your Android project?

  • Yes, I configure all require token in ConnectyCube admin console.

  • Yes, I add google-services.json file in Android Project.

This is my google-services.json file.

{
  "project_info": {
    "project_number": "948024062720",
    "firebase_url": "https://chatconnectycube-b3b85.firebaseio.com",
    "project_id": "chatconnectycube-b3b85",
    "storage_bucket": "chatconnectycube-b3b85.appspot.com"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "1:948024062720:android:f14a8bcb7bc30bb09eb9e5",
        "android_client_info": {
          "package_name": "com.example.chatconnectycubesdk"
        }
      },
      "oauth_client": [
        {
          "client_id": "948024062720-9le85u800fbqtd1gkbrmpv584bg20mvt.apps.googleusercontent.com",
          "client_type": 1,
          "android_info": {
            "package_name": "com.example.chatconnectycubesdk",
            "certificate_hash": "b81d0c07036f1cbdc7e4483e8cba343f80ca4682"
          }
        },
        {
          "client_id": "948024062720-bjjnaig93fjasb7qctjgf3ftphum6cdb.apps.googleusercontent.com",
          "client_type": 3
        }
      ],
      "api_key": [
        {
          "current_key": "AIzaSyBAKCSyeIhx-li2zBz4HOdF4xirAaoAyFY"
        }
      ],
      "services": {
        "appinvite_service": {
          "other_platform_oauth_client": [
            {
              "client_id": "948024062720-bjjnaig93fjasb7qctjgf3ftphum6cdb.apps.googleusercontent.com",
              "client_type": 3
            }
          ]
        }
      }
    }
  ],
  "configuration_version": "1"
}

@TatankaConCube

@TatankaConCube
Copy link
Contributor

hmm, it is strange (((
can you try to use another plugin for getting a token from the Android system?

@Significantinfotech2020
Copy link

Significantinfotech2020 commented Oct 23, 2020

hmm, it is strange (((
can you try to use another plugin for getting a token from the Android system?

@TatankaConCube

  • I get device Id using device_info plugin.
    This way I get deviceId
String dId = '';

  Future<String> _getId() async {
    var deviceInfo = DeviceInfoPlugin();
    if (Platform.isIOS) {
      // import 'dart:io'
      var iosDeviceInfo = await deviceInfo.iosInfo;
      setState(() {
        dId = iosDeviceInfo.identifierForVendor;
        print('IOS:::::::' + dId);
      });
      return iosDeviceInfo.identifierForVendor; // unique ID on iOS
    } else {
      var androidDeviceInfo = await deviceInfo.androidInfo;
      setState(() {
        dId = androidDeviceInfo.androidId;
        print('Android:::::::' + dId);
      });
      return androidDeviceInfo.androidId; // unique ID on Android
    }
  }
  • This is subscription() method snippet which call message send time.
Future<void> subScription() async {
    bool isProduction = bool.fromEnvironment('dart.vm.product');

    CreateSubscriptionParameters parameters = CreateSubscriptionParameters();
    parameters.environment =
        isProduction ? CubeEnvironment.PRODUCTION : CubeEnvironment.DEVELOPMENT;

    if (Platform.isAndroid) {
      parameters.channel = NotificationsChannels.GCM;
      parameters.platform = CubePlatform.ANDROID;
    } else if (Platform.isIOS) {
      parameters.channel = NotificationsChannels.APNS;
      parameters.platform = CubePlatform.IOS;
    }

    String token = await _fcm.getToken();

    String deviceId = dId;
    parameters.udid = deviceId;
    print(
        'pushToken======/*$token*/ ${_cubeDialog.getRecipientId()}...${_cubeDialog.userId}');
    parameters.pushToken =
        '${_cubeDialog.getRecipientId()}...${_cubeDialog.userId}'; /*"2b6f0cc9...4b831186";*/
    parameters.bundleIdentifier =
        ""; 

    createSubscription(parameters.getRequestParameters())
        .then((cubeSubscription) {
      print('SUBSCRIPTION SUCCESS ====> $cubeSubscription');
    }).catchError((error) {
      print('SUBSCRIPTION ERROR ==> $error');
    });
  }
  • This is my sendNotification() method
void sendPushNotification() {
    bool isProduction = bool.fromEnvironment('dart.vm.product');
    CreateEventParams params = CreateEventParams();
    params.parameters = {
      'message': 'jhfgjhbn',
      // 'message' field is required"Some message in push"
      'custom_parameter1': 'FLUTTER_NOTIFICATION_CLICK',
      //"custom parameter value 1"
      'custom_parameter2': "custom parameter value 2",
      'ios_voip': 1
      // to send VoIP push notification to iOS
      //more standard parameters you can found by link https://developers.connectycube.com/server/push_notifications?id=universal-push-notifications
    };

    params.notificationType = NotificationType.PUSH;
    params.environment =
        isProduction ? CubeEnvironment.PRODUCTION : CubeEnvironment.DEVELOPMENT;
    params.usersIds = [_cubeDialog.userId, _cubeDialog.getRecipientId()];

    createEvent(params.getEventForRequest()).then((cubeEvent) {
      print('CUBE EVENT -----> $cubeEvent');
    }).catchError((error) {
      print('CUBE EVENT ERROR -----> $error');
    });
  }
  • This is getToken() method
void getToken() {
   final connector = createPushConnector();
   if (connector.token.value != null) {
     String token = connector.token.value;
     print('Exist token: $token');
   } else {
     connector.token.addListener(() {
       String token = connector.token.value;
       print('Updated token: $token');
     });
   }
 }
  • This is init() method

void init() async {
final connector = createPushConnector();

connector.configure(
    onLaunch: onLaunch,
    onMessage: onMessage,
    onResume: onResume,
    onBackgroundMessage: onBackgroundMessage);

connector.requestNotificationPermissions();

getToken();

}


-```
 // Called when your app launched by PushNotifications

  Future<dynamic> onLaunch(Map<String, dynamic> message) {
    log('onLaunch, message: $message');
    return Future.value();
  }

// Called when your app become foreground from background by PushNotifications

Future onResume(Map<String, dynamic> message) {
log('onResume, message: $message');
return Future.value();
}


- ```
// Called when receive PushNotifications during your app is on foreground

  Future<dynamic> onMessage(Map<String, dynamic> message) {
    log('onMessage, message: $message');
    return Future.value();
  }

// Called when receive PushNotifications when app was stopped (Android only).

static Future onBackgroundMessage(Map<String, dynamic> message) {
log('onBackgroundMessage, message: $message');
if (message.containsKey('data')) {
// Handle data message
final dynamic data = message['data'];
}

if (message.containsKey('notification')) {
  // Handle notification message
  final dynamic notification = message['notification'];
}

// Or do other work.
return Future.value();

}


- This is the code snippet which I use for notification. If I made any mistake then Please suggest me asap. 

I can't get token in **getToken()** method. I think this is the main issue. How can I solve this?

@TatankaConCube
Copy link
Contributor

Yes, sure, it is the main problem. But I do not understand, which token you used before for creating a subscription?
Which version of flutter_apns plugin do you use? or just from GitHub like in our documentation?

@TatankaConCube
Copy link
Contributor

flutter_apns plugin depends on firebase_messaging plugin, please read its Readme and add needed configs to your project.

@Significantinfotech2020

@TatankaConCube

Yes, sure, it is the main problem. But I do not understand, which token you used before for creating a subscription?

I use this method for getting token

if (connector.token.value != null) {
    String token = connector.token.value;
    log('Exist token: $token');
  } else {
    connector.token.addListener(() {
      String token = connector.token.value;
      log('Updated token: $token');
    });
  }

Which version of flutter_apns plugin do you use? or just from GitHub like in our documentation?

I use flutter_apns: ^1.3.1.

@Significantinfotech2020

flutter_apns plugin depends on firebase_messaging plugin, please read its Readme and add needed configs to your project.

Dear @TatankaConCube

I already done all this requirement. I have only one confusion for this this plugin. Should I have to mention below method which is given in firebase_messaging documentation?

firebase_messaging

@TatankaConCube
Copy link
Contributor

I can't get token in getToken() method.

how you created subscriptions before without this method? Whit token you used?

Should I have to mention below method which is given in firebase_messaging documentation?

No, you don't need this method, it is just an example, how to send push notification from the app. Our server does similar logic when you create an event or send a push notification from the ConnectyCube admin panel. But you can use it for testing push notifications on your device without the Connectycube server.

@Significantinfotech2020
Copy link

Significantinfotech2020 commented Oct 24, 2020

@TatankaConCube

how you created subscriptions before without this method?

I use in all above method in this way. If I made mistake then suggest me.

void onSendChatMessage(String content) async {
    await notificationEnable();
    if (content.trim() != '') {
      final message = createCubeMsg();
      message.body = content.trim();
      await subScription();
      await init();

      sendPushNotification();
      onSendMessage(message);
    } else {
      Fluttertoast.showToast(msg: 'Nothing to send');
    }
  }

Whit token you used?

Now, I get token in init() method.

  • In init() method I use token
if (connector.token.value != null) {
      String token = connector.token.value;
      print('Exist token: $token');
    } else {
      connector.token.addListener(() {
        String token = connector.token.value;
        print('Updated token: $token');
      });
  • In subscription() method, I use this token

parameters.pushToken = '${_cubeDialog.getRecipientId()}...${_cubeDialog.userId}';

@TatankaConCube
Copy link
Contributor

Try to clear all app data, then completely remove it from the device and install it again. During writing documentation, I did the same step by step and it worked. I can't understand why it does not work for you (((

@TatankaConCube
Copy link
Contributor

parameters.pushToken it is 'key', which FCM uses for identifying your device. It is like 'receiverId' for FCM when the Connectycube server sends push notifications. It should be the only token from the system, but not any random data.

@Significantinfotech2020
Copy link

Significantinfotech2020 commented Oct 24, 2020

parameters.pushToken it is 'key', which FCM uses for identifying your device. It is like 'receiverId' for FCM when the Connectycube server sends push notifications. It should be the only token from the system, but not any random data.

@TatankaConCube
But sir I did not know hoe to get this 'key', I mean 'receiverId'. Actually, I mean where I can get this?

@Significantinfotech2020

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

  • This data I use for creating event. In this I mention all of the data which required as per documentation. Please check below code and if made mistake then please suggest me.
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
Copy link

Significantinfotech2020 commented Oct 29, 2020

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
Copy link
Contributor

it can be like:

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

@Significantinfotech2020

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
Copy link
Contributor

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

@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
Copy link
Contributor

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

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
Copy link
Contributor

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
Copy link

@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
Copy link
Contributor

@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
Copy link

Significantinfotech2020 commented Nov 5, 2020

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
Copy link
Contributor

TatankaConCube commented Nov 5, 2020

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
Copy link
Contributor

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

@Significantinfotech2020
Copy link

@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
Copy link

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
Copy link
Contributor

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

@Significantinfotech2020
Copy link

@TatankaConCube

In which way do you send push notification?

I am sending notification as per your updated code.

From admin panel?

No.

@TatankaConCube
Copy link
Contributor

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

@Significantinfotech2020
Copy link

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
Copy link
Contributor

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

@Significantinfotech2020
Copy link

@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
Copy link
Contributor

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
Copy link
Contributor

Implemented in the latest version. Closing...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants