Closed nguyenquyettienktmt closed 3 years ago
Yes, we plan to add background calls support in one of near release.
Yeahhhh, I love U 3000 <3
+1 for this awesome feature as this is essential for each VoiP App :)
Is there a way to implement this with the current API? In a background process for example with the workmanager plugin perhaps?
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.
I am trying to use Push notification for Android however, it is not working as expected. code sample:
Result:
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.
@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
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
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.
Hello @TatankaConCube
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?
So, help me to solve this issue.
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:
@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)
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.
- 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.
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
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.
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.
And you get the same error again? Right?
And you get the same error again? Right?
Yes
Did you configure the required tokens in the ConnectyCube admin console? Did you add google-services.json file to your Android project?
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
hmm, it is strange ((( can you try to use another plugin for getting a token from the Android system?
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
-
- ```
// Called when your app become foreground from background by PushNotifications
Future<dynamic> 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<dynamic> 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?
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?
flutter_apns plugin depends on firebase_messaging plugin, please read its Readme and add needed configs to your project.
@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.
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?
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.
@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.
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');
});
subscription()
method, I use this tokenparameters.pushToken = '${_cubeDialog.getRecipientId()}...${_cubeDialog.userId}';
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 (((
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.
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?
In our example it is the method getToken()
. You can try to use another plugins for getting this data.
In our example it is the method
getToken()
. You can try to use another plugins for getting this data.
@TatankaConCube
I check full code but I can't find getToken()
method. Please suggest me which plugin I should use for getting this data.
I mean this part from our doc
// getting token which used for subscription on Push Notifications on ConnectyCube server
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');
});
}
@TatankaConCube
I tried everything but I didn't get any solution. If you have demo file of notification code snippet then please share.
@Significantinfotech2020 during writing the documentation I used this draft branch for testing. There part of code related to creation subscription. You can try to add something similar to your project.
@Significantinfotech2020 during writing the documentation I used this draft branch for testing. There part of code related to creation subscription. You can try to add something similar to your project.
@TatankaConCube
I tried as you suggest, but now I got this error log from dashboard notification.
{
"notification": {
"id": 6901158,
"badge": null,
"device_token": null,
"sound": "default",
"alert": null,
"data": {
"message": "dt7vh",
"custom_parameter1": "FLUTTER_NOTIFICATION_CLICK",
"custom_parameter2": "custom parameter value 2",
"collapse_key": "event3372039"
},
"expiry": 86400,
"delivered": false,
"delivered_at": null,
"failed": true,
"failed_at": "2020-10-26T10:33:52+00:00",
"fail_after": "2020-10-26T11:33:42+00:00",
"retries": 0,
"error_code": null,
"error_description": "Unable to deliver notification 6901158, received error (Failed to deliver to recipients 0, 1. Errors: InvalidRegistration, InvalidRegistration.)",
"deliver_after": null,
"alert_is_json": null,
"app_id": 1283,
"collapse_key": null,
"delay_while_idle": false,
"registration_ids": [
"ad156f91103bd48a",
"e1f422d058f5ec16",
"d4doPAAuTUm2c6jfr-I-PM:APA91bFgD55qnOoYAk74GV5aIR6dHIMKaY4Pbz-319cY7aTjVKDcrycw7agET9I4cOwxQcfMs7uYJ38i2QAzXEjDPdOmyYbqL62kJ06OnIyq9fCcvvGuKJ9WiJMnezdX8JlXEQXkHHcP",
"ezAU2ZFgRZuuicqM9C7bTi:APA91bGPXBBtbdi5_MFSfMkOZQ80FaBlfUa-mOrh3R4jFL0XkQDcM3YAF8kqdH31XnKG75XEuZ4mFV2NR-e162QPm6mwt_3JguRohA8fARk_VOXo4rOA40MKqkEEsVbzGhLbxAZpOvzT"
],
"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": 3372039,
"event_date": "2020-10-26T10:33:42+00:00"
},
"log": [
{
"device_token": null,
"delivered_at": null,
"failed_at": "2020-10-26T10:33:52+00:00",
"error_code": null,
"error_description": "Unable to deliver notification 6901158, received error (Failed to deliver to recipients 0, 1. Errors: InvalidRegistration, InvalidRegistration.)"
}
]
}
Now, If you catch exact problem, then help me asap.
Can you get a token from FCM on the device now? Can you provide logs with the subscription creation process? Looks like you have the same error as before.
@TatankaConCube
Can you get a token from FCM on the device now?
Yes, but in firebase console when I clicked on cloud messaging tab, It has no any send notification.
Can you provide logs with the subscription creation process?
I/flutter (31956): CB-SDK: : =========================================================
I/flutter (31956): === REQUEST ==== baa7ccb0-2ad5-49b0-ae9c-2f599e13cecc ===
I/flutter (31956): REQUEST
I/flutter (31956): POST https://api.connectycube.com/subscriptions
I/flutter (31956): HEADERS
I/flutter (31956): {Content-type: application/json, ConnectyCube-REST-API-Version: 0.1.1, CB-SDK: Flutter 0.5.0, CB-Token: eb0d292af15156876556be15d5d162eeac000dd4}
I/flutter (31956): BODY
I/flutter (31956): {"notification_channel":"gcm","device":{"udid":"ad156f91103bd48a","platform":"android"},"push_token":{"environment":"development","client_identificatio
n_sequence":"d4doPAAuTUm2c6jfr-I-PM:APA91bFgD55qnOoYAk74GV5aIR6dHIMKaY4Pbz-319cY7aTjVKDcrycw7agET9I4cOwxQcfMs7uYJ38i2QAzXEjDPdOmyYbqL62kJ06OnIyq9fCcvvGuKJ9WiJMnezdX8JlXEQXk
HHcP","bundle_identifier":"com.example.chatconnectycubesdk"}}
This log I got when subscription method called.
SUBSCRIPTION SUCCESS ====> [{notification_channel: gcm, push_token: null, device: {udid: ad156f91103bd48a, platform: android}}]
Code run as success but push_token get null.
sendNotification()
method and its log is CUBE EVENT -----> [{notification_type: null, environment: development, message: {message: cfrthhu, custom_parameter1: FLUTTER_NOTIFICATION_CLICK, custom_
parameter2: custom parameter value 2}, event_type: one_shot}]
Looks like you have the same error as before.
Yes, but in dashboard when I clicked on Push Notification -> Queue tab, notification status, it displays 2 Delivered, 2 Failed and above log.
Try to remove all subscriptions in the Connectycube dashboard and do the same again (reinstall the app (delete completely and install it again), subscribe, and send push notification). And see logs from callbacks for receiving push notifications on your device, I mean them:
connector.configure(
onLaunch: onLaunch,
onMessage: onMessage,
onResume: onResume,
onBackgroundMessage: onBackgroundMessage);
Try to remove all subscriptions in the Connectycube dashboard and do the same again (reinstall the app (delete completely and install it again), subscribe, and send push notification). And see logs from in callbacks for receiving push notifications on your device, I mean them:
connector.configure( onLaunch: onLaunch, onMessage: onMessage, onResume: onResume, onBackgroundMessage: onBackgroundMessage);
@TatankaConCube
I did same step as you suggest, now I get title and body parameter null in onMessage()
method.
This is notification log from dashboard. but still I didn't get notification and any changes in firebase console cloud messaging.
{
"notification": {
"id": 6905941,
"badge": null,
"device_token": null,
"sound": "default",
"alert": null,
"data": {
"message": "hii",
"custom_parameter1": "FLUTTER_NOTIFICATION_CLICK",
"custom_parameter2": "custom parameter value 2",
"collapse_key": "event3374654"
},
"expiry": 86400,
"delivered": true,
"delivered_at": "2020-10-26T11:31:03+00:00",
"failed": null,
"failed_at": null,
"fail_after": "2020-10-26T12:31:03+00:00",
"retries": 0,
"error_code": null,
"error_description": null,
"deliver_after": null,
"alert_is_json": null,
"app_id": 1283,
"collapse_key": null,
"delay_while_idle": false,
"registration_ids": [
"exid1TofSUis39TSygwM3v:APA91bF5r8sYKWcGfMPDrL5UoqYPcQ0A8e_yz_ZEIIV6OubKb8PWG_b1z_kX1sbn96lwNYOQ5-1COx6xKcBofCIexhUOJvpihP4zUnRKCfsfuWv9Bx9htEreHHTIZreNRCcW6ab6QEg0",
"dSaTJ6IFS22N1EcVXO68NA:APA91bFLgSQEc2ezPtRSfBSEc3M_PUnkzrJYuh2dMo3PY-wRBWNaLVYEkYABCXnBHWHmI6qOehEWGkbbT8BBW_9BmsITQBlB_dlX_397r7xmPc8U0T3avxZhCN8HyQ770EstdtwR41Lt"
],
"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": 3374654,
"event_date": "2020-10-26T11:31:02+00:00"
},
"log": [
{
"device_token": null,
"delivered_at": "2020-10-26T11:31:03+00:00",
"failed_at": null,
"error_code": null,
"error_description": null
}
]
}
I did same step as you suggest, now I get title and body parameter null in onMessage() method.
does it mean you receive a push notification on the device?
FYI, ConnectyCube server sends push notification with type 'data' not 'notification' it means you have search your data in parameter 'data', like in my draft code
does it mean you receive a push notification on the device?
@TatankaConCube
No, I don't receive notification on device but only got above log. Also there is nothing changes in firebase console.
what means it?
now I get title and body parameter null in onMessage() method
In the log I can't see any errors, it means the Connectycube server successfully sent a push notification to FCM server. Please add logs to all callbacks and try to send push notification again.
"delivered": true,
"delivered_at": "2020-10-26T11:31:03+00:00",
it means push notification successfully delivered to FCM server
Dear @TatankaConCube
For Firebase connection with connectycube_sdk, I have confusions are that
Should I have to enable any authentication sign-in option filed like email/password or phone in firebase console?
While using firebase_messaging packages to configure project, I have to define this two steps in my project or not?
5. Define a TOP-LEVEL or STATIC function to handle background messages
Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) async {
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.
}
Note: the protocol of data and notification are in line with the fields defined by a RemoteMessage.
6. Set onBackgroundMessage handler when calling configure
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print("onMessage: $message");
_showItemDialog(message);
},
onBackgroundMessage: myBackgroundMessageHandler,
onLaunch: (Map<String, dynamic> message) async {
print("onLaunch: $message");
_navigateToItemDetail(message);
},
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
_navigateToItemDetail(message);
},
);
Note: configure should be called early in the lifecycle of your application so that it can be ready to receive messages as early as possible. See the example app for a demonstration.
Because this two method is same as connectycube_sdk methods. That's why I have this confusion?
Dear @TatankaConCube
For Firebase connection with connectycube_sdk, I have confusions are that
- Should I have to enable any authentication sign-in option filed like email/password or phone in firebase console?
- While using firebase_messaging packages to configure project, I have to define this two steps in my project or not?
5. Define a TOP-LEVEL or STATIC function to handle background messages
Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) async { 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. }
Note: the protocol of data and notification are in line with the fields defined by a RemoteMessage.
6. Set onBackgroundMessage handler when calling configure
_firebaseMessaging.configure( onMessage: (Map<String, dynamic> message) async { print("onMessage: $message"); _showItemDialog(message); }, onBackgroundMessage: myBackgroundMessageHandler, onLaunch: (Map<String, dynamic> message) async { print("onLaunch: $message"); _navigateToItemDetail(message); }, onResume: (Map<String, dynamic> message) async { print("onResume: $message"); _navigateToItemDetail(message); }, );
Note: configure should be called early in the lifecycle of your application so that it can be ready to receive messages as early as possible. See the example app for a demonstration.
Because this two method is same as connectycube_sdk methods. That's why I have this confusion?
@TatankaConCube
Please give me answer asap for my confusion.
From the Firebase console you need:
I have to define this two steps in my project or not?
yes, you have to create this static method and set it as the listener for the onBackgroundMessage
callback.
@TatankaConCube
you have to create this static method and set it as the listener for the
onBackgroundMessage
callback.
Please help me how and where I have to change in code snippet. I mean in init()
method I have to initialize any function?
you can initialize plugin in method void initState()
of your widget where you have logged in user. In this place, you can set listeners for events. The main thing - you have to do this immediately when you got logged in user.
@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.
I hope that, connectycube-flutter lib, will be support call method when application on close or background for Android and IOS.