【发布时间】:2016-11-04 08:41:17
【问题描述】:
在应用被终止后,我无法通过 HTTP 请求通过 Firebase 向我的 iOS 设备发送推送通知。当应用程序在前台或在后台活动时,一切都按预期工作。但是,如果我杀死该应用程序,它将无法正常工作。如果应用程序被终止,我可以通过 Firebase 控制台向我的应用程序发送通知,因此我认为我使用的代码一定有问题。
这是我发送推送通知的代码:
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);
}
}
我在这里忘记了什么吗?这适用于在前台、后台和应用程序被终止时向 Android 设备发送推送通知,就像我对前台和后台的 iOS 设备所说的那样。
唯一的问题是当应用被终止时向 iOS 设备发送推送通知。有谁知道我将如何解决这个问题?
【问题讨论】:
标签: ios firebase push-notification apple-push-notifications firebase-cloud-messaging