Sending push notification from android to ios via pubnub - android

I'am trying to send push notification with pubnub from android app to ios app. I'am using folowing json as push notificatio message, it works for android but doesn't work for ios:
{
"pn_gcm": {
"message": "test message",
"message_id": 1464707948327,
"sender_id": "5735b2a2a3c4c3fe01d37600",
"chat_room": "",
"message_type": "text",
"date": 1464707948327,
"file_url": "",
"sender_name": "Sorocean Alexei"
},
"pn_apns": {
"aps": {
"payload": {
"message": "test message",
"message_id": 1464707948327,
"sender_id": "5735b2a2a3c4c3fe01d37600",
"chat_room": "",
"message_type": "text",
"date": 1464707948327,
"file_url": "",
"sender_name": "sender name"
},
"alert": "sender name: test message",
"badge": 1,
"sound": "default"
}
}
}

Related

Not getting Pubnub payload in bundle from Notification tray. When app is killed

I have integrated pubnub API in one of my project. I am trying to get bundle of data that i have sent in payload. I have added FCM for push notification. I am getting push notification in all cases but not getting bundle data when app is killed or in background. Already getting payload object when app is in foreground but not getting any data when app is in background or killed.
Payload 1 :
{
"pn_gcm": {
"notification": {
"title": "Barack Obama",
"body": "12",
"channelName": "Hell 4_656"
}
},
"firstName": "Barack",
"lastName": "Obama",
"displayName": "Barack Obama",
"profileImageUrl": "abcURL",
"userId": "173",
"type": "sender",
"time": "1615958943297",
"message": "12"
}
PayLoad 2 :
{
pn_gcm={
notification={
title=BarackObama,
body=Hello,
image=Hell4_656
}
},
firstName=Barack,
lastName=Obama,
displayName=BarackObama,
time=1615958740553,
type=sender,
message=Hello,
profileImageUrl=abcURL,
userId=173
}
I am getting notification object when app is in foreground but not getting any of them when app is in background or killed.(Getting some FCM default object)
I am trying to get notification object in bundle when launch app from Notification tray
Answer
Made JSON payload like this :
{
"pn_gcm": {
"notification": {
"title": "Barack Obama",
"body": "18"
},
"body": {
"channelName": "Hell 5_657",
"firstName": "Barack",
"lastName": "Obama",
"displayName": "Barack Obama",
"profileImageUrl":
"http://3.137.127.137/quiqle/uploads/profile/1615523786_4866.jpg",
"userId": "173",
"type": "sender",
"time": "1615965488916",
"message": "18"
}
}
}
You need to add data with information which you want to receive with push into pn_gcm.
Information outside of pn_(gcm|apns) (including tjpse) will be delivered as regular messages
Message can be as follows:
using notification:
{
"pn_gcm":{
"notification":{
"title":"Chat invitation",
"body":"John invited you to chat",
"sound":"default"
}
}
}
Or using data:
{
"pn_gcm" : {
"data" : {
"room" : "Portugal vs Denmark",
"body" : "great match!"
}
}
}
or both:
{
"pn_gcm" : {
"notification": {
"title":"Portugal vs Denmark",
"body":"great match!"
},
"data" : {
"room" : "Portugal vs Denmark",
"body" : "great match!"
}
}
}
For an explanation on the different between data and notification, please read the official FCM docs, About FCM messages.
See also:
Why are my FCM push notifications not working?

Firebase payload json for cross platforms are not working

I'm using Firebase to send message across iOS & Android devices. I follow the document of google but it's still not working.
https://firebase.google.com/docs/cloud-messaging/concept-options
In the document, they gave an example
{
"message":{
"token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification":{
"title":"Match update",
"body":"Arsenal goal in added time, score is now 3-0"
},
"android":{
"ttl":"86400s",
"notification"{
"click_action":"OPEN_ACTIVITY_1"
}
},
"apns": {
"headers": {
"apns-priority": "5",
},
"payload": {
"aps": {
"category": "NEW_MESSAGE_CATEGORY"
}
}
},
"webpush":{
"headers":{
"TTL":"86400"
}
}
}
}
and I replaced some placeholders of this example with my Firebase configurations then I ran Postman and it returned 400 bad Request
{
"message":{
"token":"dRnhMNngY02mofqQ-5no8K:APA91bEcaaZ3QBWTdZfN3hU1tJzy6_ChW4FMArXbbWvT-8wq11TDN2jLy7uaT-Wzjq_xAzPqZfVje5_n54pVLnCfUUPTp_EuS3CykGnysHO0BeJn0TEgP-czc_y2kdyVMW-39mlSh8-t",
"notification":{
"title":"Match update",
"body":"Arsenal goal in added time, score is now 3-0"
},
"android":{
"ttl":"86400s",
"notification": {
"click_action":"OPEN_ACTIVITY_1"
}
},
"apns": {
"headers": {
"apns-priority": "5"
},
"payload": {
"aps": {
"category": "NEW_MESSAGE_CATEGORY"
}
}
},
"webpush":{
"headers":{
"TTL":"86400"
}
}
}
}
But when I changed it. Set to & notification to the first level of json. My iOS device displayed a notification.
{
"to": "dRnhMNngY02mofqQ-5no8K:APA91bEcaaZ3QBWTdZfN3hU1tJzy6_ChW4FMArXbbWvT-8wq11TDN2jLy7uaT-Wzjq_xAzPqZfVje5_n54pVLnCfUUPTp_EuS3CykGnysHO0BeJn0TEgP-czc_y2kdyVMW-39mlSh8-t",
"notification": {
"title": "Match update",
"body": "Arsenal goal in added time, score is now 3-0"
}"message": {
"token": "dRnhMNngY02mofqQ-5no8K:APA91bEcaaZ3QBWTdZfN3hU1tJzy6_ChW4FMArXbbWvT-8wq11TDN2jLy7uaT-Wzjq_xAzPqZfVje5_n54pVLnCfUUPTp_EuS3CykGnysHO0BeJn0TEgP-czc_y2kdyVMW-39mlSh8-t",
"notification": {
"title": "Match update",
"body": "Arsenal goal in added time, score is now 3-0"
},
"android": {
"ttl": "86400s",
"notification": {
"click_action": "OPEN_ACTIVITY_1"
}
},
"apns": {
"headers": {
"apns-priority": "5"
},
"payload": {
"aps": {
"category": "NEW_MESSAGE_CATEGORY"
}
}
},
"webpush": {
"headers": {
"TTL": "86400"
}
}
}
}
I don't know why the example of Firebase from Google is not working? Moreover, I tried to send to my Android device, it said "InvalidRegistration" message but when I tested sending message in https://console.firebase.google.com -> Cloud Messaging -> Compose notification. I pasted the same token that I used to test Android and it worked...
Really confused?!
I found several articles and test but it did work for me. I just want to have a structure of json file to work for both iOS and Android (also need to send both type of message as: notification & data)
Can anyone help me to fix this issue?
Thank you a lot,
Just want to up this question and not to be missed

how to send image in notification in android using firebase?

I am trying to send image in push notification from firebase console but it doesn't work, so i tried to send from the postman but it doesn't work either. I tried other parameters like icon, image, media_url, mediaImgUrl..etc from Internet in the body.
Help me out here so that i can send image in notification.
{
"to": "tokennnnnnnnnnnn............",
"content_available": true,
"mutable_content": true,
"data":
{
"message": "Hey!",
"icon": ".....farm.png"
},
"notification":
{
"body": "Topic",
"sound": "default",
"icon": ".....farm.png"
}
}
Try sending image with this payload :
{
"message":{
"token" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"android": {
"notification": {
"body" : "This is an FCM notification that displays an image.!",
"title" : "FCM Notification",
"image": "url-to-image"
}
}
}

API integration with get and post URL in android

for save the user - http://aeps.gear.host/api/Test/SaveUser
INPUT
{
"Name": "sample",
"EmailId": "sample#gmail.com",
"MobileNo": "9876543210",
"Gender": "MALE",
"Latitude": "99.99",
"Longitude": "99.99",
"Birthdate": "05-03-2017"
}
OUTPUT
{
"$id": "1",
"Status": true,
"Data": "[{}]",
"Message": "Details saved successfully"
}
for get user
2) http://aeps.gear.host/api/Test/GetDetails
INPUT
{
"RegistrationId": "0"
}
OUTPUT
{
"$id": "1",
"Status": true,
"Data": [
{
"$id": "2",
"RegistrationId": 1,
"Name": "sample string 1",
"EmailId": "sample string 2",
"MobileNo": "sample string 3",
"Gender": "sample string 4",
"Latitude": "sample string 6",
"Longitude": "01-01-1900",
"Birthdate": "sample string 5"
}
],
"Message": "List generated successfully"
}
I want to Register the user details in registration screen and show all registered users in view user screen in android. I have a URL for get and post both with json response.
I want the user to register with name, mail , number and want to show in a simple list in next screen

FCM Diagnostics Invalid Message ID?

I am using GCM to send push messages to multiple users, but even though I am getting success and message IDs in the response, I cannot debug them in FCM diagnostics and they don't arrive to the devices.
How can I debug this?
The message I'm sending:
{
"priority": "normal",
"time_to_live": 6000,
"delay_while_idle": true,
"content_available": true,
"notification": {
"title": "Title",
"text": "Text",
},
"data": {
"title": "Title",
"text": "Text",
},
"registration_ids": ["ID1", "ID2"]
}
The response is an array of message IDs.

Categories

Resources