ios - iOS App在后台或未运行时如何响应iOS APNS事件

标签 ios apple-push-notifications

我正在通过 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.

我在这里缺少什么?

  1. 在 iOS 中是否有任何方法可以在不涉及用户的情况下使未运行的应用程序运行起来以响应 APNS 通知或消息?

  2. 是否有可能在 iOS 下让 App 永久运行(即自动启动),以便它始终响应通知或消息?

最佳答案

您正在发送“数据消息” - 这对于未运行的应用程序不起作用。这是非常缺乏记录的,但你必须发送“通知消息”来唤醒你的应用程序。只需添加

"notification":{
       "title" : "title",
       "body" : "body"
 },

您的消息以使其正常工作

关于ios - iOS App在后台或未运行时如何响应iOS APNS事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58833458/

相关文章:

iphone - iOS : Date conversion results in wrong date

json - 通过套接字发送表情符号时出现 Perl 问题

ios - iOS,先强制退出应用程序,点击接收通知横幅后,应用程序启动失败

ios - AWS SNS 无法使用 createPlatformEndpoint

ios - 是否可以在从 iOS 端在设备上显示之前更改推送通知消息?

ios - Firebase Cloud Messaging 推送通知不再出现在 iOS 上

ios - UIWebView iOS 中的客户端证书身份验证

ios - iOS 上使用 Memory Monitor 时虚拟内存消耗和实际内存的区别

ios - 有没有办法根据计算以编程方式更改 UIStepper 的值?

ios - 从 Xcode 6 仅将单个开发人员帐户导出到 .developerprofile