首页 文章

处理来自onMessageReceived的数据和通知有效负载的消息

提问于
浏览
1

我需要发送包含“数据”和“通知”有效负载的消息 . 该消息将被发送到一个主题,该主题可以来自iOS或Android设备 .

在Android中,是否有任何方式可以在onMessageReceived上收到通知和数据有效负载而不是系统托盘和意图附加内容的消息?这包括应用程序在后台时的情况 .

我无法删除通知有效负载(仅发送'数据'有效负载),因为iOS用户需要通知有效负载

1 回答

  • 0

    也许如果有帮助,这就是我用来为IOS和Android发送通知的(C#)对象 .

    internal class jsonObj
        {
            //public bool delay_while_idle { get; set; }
            public data data { get; set; }
            public notification notification { get; set; }
            public string to { get; set; }
            public string priority { get; set; }
        }
    
        internal class data
        {
            public int Id { get; set; }
            public int commentId { get; set; }
            public string type { get; set; }
            public string DisplayName { get; set; }
            public string licensePlateCode { get; set; }
            public int licensePlateId { get; set; }
            public string text { get; set; }
        }
    
        internal class notification
        {
            public string title { get; set; }
            public string body { get; set; }
            public string sound { get; set; }
            public string badge { get; set; }
            [JsonProperty("content-available")]
            public string contentAvailable { get; set; }
        }
    

    在编写代码的那一刻,我在android中使用了旧的 WakefulBroadcastReceiverIntentService ,不再推荐了 . 但如果有兴趣,它看起来像this question

    EDIT: OP评论了this post on github . 那里描述了同样的问题,但仍未解决(2016年9月) . 可以在那里找到解决方法,您必须发送不同的IOS和Android请求 .

相关问题