How to know "topic" name from Firebase notification on iOS - ios

I'm trying to use Firebase in my iOS application. I successfully integrated it and receiving notifications from all 3 Targets (user segment, topic and single device). My question is how to know a particular notification is received from which topic?
I'm following this documentation and this github page
EDIT:
I'm testing on iOS11.2 (XCode9.2) & my response (userInfo) is:
{
aps = {
alert = test;
sound = default;
};
"gcm.message_id" = "0:1513282329413512%38894e8e28894e8e";
"gcm.n.e" = 1;
"gcm.notification.sound2" = default;
"google.c.a.c_id" = 1542306492273623048;
"google.c.a.c_l" = test;
"google.c.a.e" = 1;
"google.c.a.ts" = 1513182256;
"google.c.a.udt" = 0;
}
I'm getting gcm.message_id but it looks like "gcm.message_id" = "0:1512894251264950%38894e8e38894e8e"; How to map this to my topic name?
Thanks.

I got the answer from Firebase support team.
It doesn't seem like there's a way to get this info as per
documentation. One workaround I can think of is if you would pass the
topic name in your data payload, you can then manually handle it from
your code and map it to your message_id.
So looks like this works on Android but on iOS it's not supported today (Dec 2017)

Related

Deep Link does not contain valid required params - Flutter with Firebase Dynamic Link

I am using Firebase dynamic link in my flutter app. I am allowing user to generate dynamic link in app that can be shared via sms/email/whatsApp etc etc.
This link is working fine for Android but for iOS i am getting this exception.
Thanks in advance.
Below is my Xcode log.
[Firebase/Analytics][I-ACS023001] Deep Link does not contain valid required params. URL params: {
"_cpb" = 1;
"_cpt" = cpit;
"_fpb" = "XXAHEJ4DGgVlbXXXXX==";
"_iumchkactval" = 1;
"_iumenbl" = 1;
"_osl" = "https://app.XXXXXXX.com/PPZbgKsKpKvukDWZ8";
"_plt" = 1400;
"_uit" = 1400;
amv = 1;
apn = "com.xxx.xxxx";
cid = 000000;
ibi = "com.xxx.xxxx";
imv = 1;
isi = X4967XXXXX;
link = "https://app.xxxxx.com/data?userid=Bzhm1TScavV2&refcode=3DWIN11329206";
}
below are my firebase dynamic link details
Link name
Invite Friends
Deep link
https://app.xxxxx.com/data?userid=Bzhm1TScavV2&refcode=WIN11329206
Android app
com.xxx.xxxx
iOS app
com.xxx.xxxx
Long Dynamic Link
https://app.xxxxx.com/?link=https://app.xxxxx.com/data?userid%3DBzhm1TScavV2%26refcode%3DWIN11329206&apn=com.xxx.xxxx&isi=X4967XXXXX&ibi= com.xxx.xxxx
Short Dynamic Link
https://app.xxxxx.com/invitefriends
This issue seems to be present on older version of firebase_dynamic_links as discussed on this issue ticket. A workaround for this issue is to use app_links when the link is launched in iOS.
import 'dart:io' show Platform;
...
if (Platform.isIOS) {
// Handle link using app_links in iOS
initDynamicLinksIOS();
}
else {
// Use the firebase_dynamic_links per usual
initDynamicLinksAndroid();
}
Then use app_links to handle the deep link in iOS.
initDynamicLinkIOS() async {
final _appLinks = AppLinks(
// Called when a new uri has been redirected to the app
onAppLink: (Uri deepLink) async {
final PendingDynamicLinkData data =
await FirebaseDynamicLinks.instance.getDynamicLink(deepLink);
deepLink = data?.link;
if (deepLink != null) {
debugPrint('$deepLink');
// Handle the deep link
}
},
);
}

Send push notification to iOS device via Firebase (FCM) using HTTP Request after app is killed [duplicate]

This question already has answers here:
Can't send push notifications using the server API
(4 answers)
Closed 6 years ago.
I am having trouble sending push notifications via Firebase through HTTP Request to my iOS device after the app is killed. When the app is in the foreground or active in the background everything work as expected. But if I kill the app it won't work. I am able to send notifications to my app through the Firebase console if the app is killed, so I believe something must be wrong with the code I am using.
This is my code for sending the push notification:
private void SendPushNotification(string devicetoken, string header, string content, string pushdescription)
{
var textNotification = new
{
to = devicetoken,
notification = new
{
title = header,
text = content,
content_available = true,
sound = "enabled",
priority = "high",
id = pushdescription,
},
project_id = "rrp-mobile",
};
var senderId = "212579566459";
var notificationJson = Newtonsoft.Json.JsonConvert.SerializeObject(textNotification);
using (var client = new WebClient())
{
client.Encoding = Encoding.UTF8;
client.Headers[HttpRequestHeader.ContentType] = "application/json";
client.Headers[HttpRequestHeader.Authorization] = "key=AIfrSyAtgsWCMH4s_bOyj-Us4CrdsifHv-GqElg";
client.Headers["Sender"] = $"id={senderId}";
client.Headers[HttpRequestHeader.ContentType] = "application/json";
client.UploadString("https://fcm.googleapis.com/fcm/send", "POST", notificationJson);
}
}
Am I forgetting something here? This works for sending push notifications to Android devices both in foreground, background and when app is killed, and like I said also to iOS devices in foreground and background.
The only issue is sending push notifications to iOS devices when the app has been killed. Does anyone have any idea as to how I would solve this issue?
I just realized my mistake, and it was very simple. I am posting this here because I believe this may be an easy thing to miss.
var textNotification = new
{
to = devicetoken,
notification = new
{
title = header,
text = content,
content_available = true,
sound = "enabled",
**priority = "high",**
id = pushdescription,
},
project_id = "rrp-mobile",
};
You need to make sure that the priority property is defined outside the "notification" scope, like this:
var textNotification = new
{
to = devicetoken,
**priority = "high",**
notification = new
{
title = header,
text = content,
content_available = true,
sound = "enabled",
id = pushdescription,
},
project_id = "rrp-mobile",
};
This will make your push notifications deliver even if the app is killed.

Firebase FCM IOS don´t send Apple apns payload

I have 3 apps, 2 are working well and are receiving pushs from FCM, but one of them does not receive pushs.
I don´t know why, but my other apps receive a Push Notification like this:
{
aps = {
alert = {
body = "body here";
title = "title here;
};
badge = 3;
"content-available" = 1;
};
"gcm.message_id" = "0:1468862214187339%9c127a139c127a13";
}
But in my other app, I receive messages like this (without aps body):
{
"collapse_key" = "...";
from = 1003897668292;
notification = {
body = "body here";
e = 1;
title = "title here";
};
}
Well, so I have some questions?
I did the same process in both applications.
I use the default swizzling
I created the p12 certificate to send Push Messages and I did upload it to the Firebase Console.
Does anyone know any reason for Firebase send messages with a different format? On the server I'm sending messages in the same way.
I would like to receive messages with the "aps/alert/body" format.
kind regards

Missing topic name when "content_available" is set

we're trying to integrate GCM messaging on our iOS app. We use topic messaging to send messages to a group of devices subscribed to the same topic.
During the developemnt we noticed that enabling the "content_available" flag to let the app receive notifications while in background the message we receive is missing the topic name, so if the app is subscribed to multiple topics we're not able to determine which topic was the sender of the message.
Notification sent using HTTP api:
{
"to":"/topics/user_5",
"data":{"action":"sync","what":"user"},
"collapse_key":"866c9b6f36461511697a5089fe4b0d8e",
"delay_while_idle":true
}
Notification received on iOS:
{
action = sync;
"collapse_key" = 866c9b6f36461511697a5089fe4b0d8e;
from = "/topics/user_5";
what = user;
}
Notification sent using HTTP api, with "content_available" flag set to true:
{
"to":"/topics/user_5",
"data":{"action":"sync","what":"user"},
"collapse_key":"866c9b6f36461511697a5089fe4b0d8e",
"content_available":true,
"delay_while_idle":true
}
Notification received on iOS:
{
action = sync;
aps = {
"content-available" = 1;
};
"gcm.message_id" = "0:1436954611368845%1f9e30f91f9e30f9";
what = user;
}
Is it the expected behaviour or is it a GCM bug? Is there someone else struggling with the same thing?

Unable to send iOS MDM Push Notification using Push Sharp

I am attempting to send the an MDM push notification to an iPad using the production APN server. However, Push Sharp says that the notification failed because the identifier is equal to 1. The following code from the PushSharp code base illustrates how it comes to that conclusion...
//We now expect apple to close the connection on us anyway, so let's try and close things
// up here as well to get a head start
//Hopefully this way we have less messages written to the stream that we have to requeue
try { stream.Close(); stream.Dispose(); }
catch { }
//Get the enhanced format response
// byte 0 is always '1', byte 1 is the status, bytes 2,3,4,5 are the identifier of the notification
var identifier = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(readBuffer, 2));
int failedNotificationIndex = -1;
SentNotification failedNotification = null;
//Try and find the failed notification in our sent list
for (int i = 0; i < sentNotifications.Count; i++)
{
var n = sentNotifications[i];
if (n.Identifier.Equals(identifier))
{
failedNotificationIndex = i;
failedNotification = n;
break;
}
}
Basically, after the writing the payload to the stream, it attempts to close the connection, during which it expects a response from the APN service, which I think it refers to as the notification identifier.
I have plugged the device into the iPhone Device Configuration utility, but nothing appears in the console, hence I assume that it never receives this notification.
My questions are...
What is this identifier that it is expecting ?
Is there anything that I am doing wrong ?
The device is running iOS 6. The structure of the payload is as follows...
{"aps":{},"mdm":"80369651-5802-40A2-A0AE-FCCF02F99589"}
The values in the returned byte[] of 6 bytes are as follows 8,8,0,0,0,1
No idea, I've never looked into the details how PushSharp deals with the APNS internals.
You shouldn't send the "aps":{} part in the notification payload, so maybe that's the reason the APNS fails the notification.
I'm sucessfully using PushSharp 1.0.17 with the following code for MDM notifications, so it definitely works in general.
var pushService = new PushService();
// attach event listeners
// override the production/development auto-detection as it doesn't
// work for MDM certificates
var cert = null; // load your push client certificate
var channel = new ApplePushChannelSettings(true, cert, true);
pushService.StartApplePushService(channel);
// create and send the notification
var notification = NotificationFactory
.Apple()
.ForDeviceToken("your-device-token-received-from-checkin")
.WithExpiry(DateTime.UtcNow.AddDays(1))
.WithCustomItem("mdm", "your-push-magic-received-in-checkin");
pushService.QueueNotification(notification);
For PushSharp v3.0+, you should be able to include directly in the Payload of the ApnsNotification.
public void SendIosMdm(string deviceToken, string pushMagic)
{
_apnsBroker.QueueNotification(new ApnsNotification
{
DeviceToken = deviceToken,
Payload = JObject.FromObject(new {
mdm = pushMagic
})
});
}

Resources