我正在通过 APNS 从 FCM 向我的 iOS 应用程序发送通知和数据消息(非通知),并且在前台一切正常。
我希望能够在应用程序处于后台时触发代码。
我已经在 info.plist
中设置了“启用后台模式”“远程通知”
但是,直到我将应用程序置于前台后,才会触发以下消息
message = new Message()
{
Apns = new ApnsConfig()
{
Headers = new Dictionary<string, string>()
{
{ "content_available", "true" },
},
},
Data = new Dictionary<string, string>()
{
{"temperature", "warm"},
},
Topic = "thetopic",
};
1) 谁能告诉我为什么这不会立即运行。我尝试添加
{
"apns-priority", "10"
},
但这没有什么区别,而且确实 Local and Remote Notification Programming Guide
声明
It is an error to use this priority for a push notification that contains only the content-available key.
我在这里缺少什么?
在 iOS 中是否有任何方法可以在不涉及用户的情况下使未运行的应用程序运行起来以响应 APNS 通知或消息?
是否有可能在 iOS 下让 App 永久运行(即自动启动),以便它始终响应通知或消息?
最佳答案
您正在发送“数据消息” - 这对于未运行的应用程序不起作用。这是非常缺乏记录的,但你必须发送“通知消息”来唤醒你的应用程序。只需添加
"notification":{
"title" : "title",
"body" : "body"
},
您的消息以使其正常工作
关于ios - iOS App在后台或未运行时如何响应iOS APNS事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58833458/