I am using PushSharp HTTP2 library to send the notification. Notification is working perfectly fine in English but when I send in Arabic, I receive it as question marks "??????????"
string message="test";
notificationModel.APS.Add("alert", message.Substring(0, Math.Min(message.Length, 160)));
notificationModel.APS.Add("badge", currentUnReadCount);
notificationModel.APS.Add("type", type);
notificationModel.APS.Add("sound", ringtone);
notificationModel.APS.Add("notification-id", notification.Id);
notificationModel.APS.Add("milestone-prize", MilestoneRedeem);
notificationModel.APS.Add("redirect_action", notification.WebUrl);
ApnsHttp2Notification appleNotification = new ApnsHttp2Notification
{
DeviceToken = currDevice.AppPushToken,
Payload = JObject.Parse(JsonConvert.SerializeObject(notificationModel)),
Tag = new PushNotificationAudience()
{
PushNotificationId = notification.Id,
UserDeviceId = currDevice.Id,
IsRead = false
},
Topic = certificate.BundleId,
};
iOsBroker.QueueNotification(appleNotification);
Related
I want to use firebase to send push notification to ios ,
I implement the frontend part and retrieve the device token correctly..
when I try to send notification from Firebase console recceived the notification successffully on ios app.
I tried sending the from my Dotnet core C# APi but not received the notification on ios.
ANy one please share how to send push notification from C# code to ios using firebase.
Install FirebaseAdmin from https://www.nuget.org/packages/FirebaseAdmin/
more details here C# Send Push Notification Firebase Cloud Messaging
the notification content
FirebaseAdmin.Messaging.Notification notification = new FirebaseAdmin.Messaging.Notification();
notification.Body = Message;
notification.ImageUrl = ImageUrl ;
notification.Title = Title ;
FirebaseAdmin.Messaging.AndroidNotification androidNotification = new FirebaseAdmin.Messaging.AndroidNotification();
androidNotification.Body = Message;
androidNotification.Color = "#2D82FF";
androidNotification.ImageUrl = ImageUrl ;
androidNotification.Title = Title ;
androidNotification.ChannelId = "12";
androidNotification.Icon = "Icon" ;
androidNotification.Sound = "default";
FirebaseAdmin.Messaging.AndroidConfig androidConfig = new FirebaseAdmin.Messaging.AndroidConfig();
androidConfig.CollapseKey = CollapseKey Id;
androidConfig.Priority = FirebaseAdmin.Messaging.Priority.High;
androidConfig.Notification = androidNotification;
androidConfig.TimeToLive = new TimeSpan(24, 0, 0);
var msg = new FirebaseAdmin.Messaging.Message();
msg.Notification = notification;
msg.Android = androidConfig;
msg.Token = LastDeviceFCMToken;
try
{
await FirebaseAdmin.Messaging.FirebaseMessaging.DefaultInstance.SendAsync(msg);
}
catch (Exception e)
{
}
with this declaration of notification, anyway will be your target Android or Ios will revice the notification
I'm trying to send background notification to my app with the Firebase Admin SDK for C# .Net Core. I'm able to do this using apple APN https endpoints (So I know the app is setup to handle this).
When I run the below code I'm getting the success message back from Firebase BUT the app is not receiving the message. When I do an Alert notification I see that on the phone as expect, it is just the background notification that seems to get lost.
var fireMessages = new List<FireMessage>()
{
new FireMessage()
{
Data = new Dictionary<string, string>(){{"type","update"}},
Token = token,
Apns = new ApnsConfig
{
Headers = new Dictionary<string, string>
{
{"apns-id", Guid.NewGuid().ToString("D")},
{"apns-push-type", "background"},
{"apns-priority", "10"},
{"apns-topic", "com.namespace.dev"},
},
Aps = new Aps
{
ContentAvailable = true
}
}
}
};
var firebaseApp = FirebaseApp.GetInstance(instanceName);
var batchResponse = await FirebaseMessaging.GetMessaging(firebaseApp).SendAllAsync(fireMessages);
if(batchResponse.FailureCount == 0){
return true;
}
return false;
I am using the Firebase .net Admin SDK on my back end to send push notifications.
According to this link I should be able to add the following json into a message object that will open the set link when the notification is clicked on while the app is in background.
"webpush": {
"fcm_options": {
"link": "https://dummypage.com"
}
I have read through the .net Admin Sdk documentation but cannot figure out where to add this.
Here is the code that I used to new up the message object
var fcm = FirebaseAdmin.Messaging.FirebaseMessaging.DefaultInstance;
var Message = new Message()
{
Notification = new Notification
{
Title = title,
Body = message,
},
Token = user.PushTokenWeb,
};
var result = await fcm.SendAsync(Message);
Does anyone know where I would set the callback link?
In FirebaseAdmin .net v1.9.0 you can
var message = new Message()
{
Token = token,
Notification = new Notification()
{
Body = notificationBody,
Title = title
},
Android = new AndroidConfig()
{
Priority = Priority.High
},
Webpush = new WebpushConfig()
{
FcmOptions = new WebpushFcmOptions()
{
Link= "https://www.davnec.eu/aurora-boreale/previsioni/"
}
}
};
.NET SDK does not support this setting yet. It's only exposed in Node.js and Go at the moment. You can provide a pull request at https://github.com/firebase/firebase-admin-dotnet to implement this feature.
I am using pushSharp library. I see deviceToken in sample code
https://github.com/Redth/PushSharp
Can anybody help me how to get that ? pushSharp sample code doesn't explain that
apnsBroker.QueueNotification (new ApnsNotification {
DeviceToken = deviceToken,
Payload = JObject.Parse ("{\"aps\":{\"badge\":7}}")
Same for Android, How to get Resistation ID's
foreach (var regId in MY_REGISTRATION_IDS) {
// Queue a notification to send
gcmBroker.QueueNotification (new GcmNotification {
RegistrationIds = new List<string> {
regId
},
Data = JObject.Parse ("{ \"somekey\" : \"somevalue\" }")
});
}
I am sending push notification via my service layer which is developed in C#.
I am not sure why I can't receive any notification from AmazonSNS. Am I missing something in my code? I am using the latest version of AWSSDK for Windows Store App by the way.
Here's my code so far.
d("init AmazonSimpleNotificationServiceClient");
AmazonSimpleNotificationServiceClient sns = new AmazonSimpleNotificationServiceClient("secret", "secret", RegionEndpoint.EUWest1);
d("get notification channel uri");
string channel = string.Empty;
var channelOperation = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
channelOperation.PushNotificationReceived += ChannelOperation_PushNotificationReceived;
d("creating platform endpoint request");
CreatePlatformEndpointRequest epReq = new CreatePlatformEndpointRequest();
epReq.PlatformApplicationArn = "arn:aws:sns:eu-west-1:X413XXXX310X:app/WNS/Device";
d("token: " + channelOperation.Uri.ToString());
epReq.Token = channelOperation.Uri.ToString();
d("creat plateform endpoint");
CreatePlatformEndpointResponse epRes = await sns.CreatePlatformEndpointAsync(epReq);
d("endpoint arn: " + epRes.EndpointArn);
d("subscribe to topic");
SubscribeResponse subsResp = await sns.SubscribeAsync(new SubscribeRequest()
{
TopicArn = "arn:aws:sns:eu-west-1:X413XXXX310X:Topic",
Protocol = "application",
Endpoint = epRes.EndpointArn
});
private void ChannelOperation_PushNotificationReceived(Windows.Networking.PushNotifications.PushNotificationChannel sender, Windows.Networking.PushNotifications.PushNotificationReceivedEventArgs args)
{
Debug.WriteLine("receiving something");
}
this is actually working after enabling Toast on .appxmanifest
I get notified everytime I publish a RAW message from Amazon SNS console. I am not receiving a JSON though which I actually need.