使用推送通知发送数据 - 也不返回整个推送 [英] send data with push notification - not returning whole push either

查看:44
本文介绍了使用推送通知发送数据 - 也不返回整个推送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了大约 2 天来让这个聊天应用程序正常工作(非常基本),当一个用户发送消息时,它会在其他用户屏幕上作为远程通知弹出,当他们打开它时,它必须将第二个用户带到特定聊天(与发送消息的用户,而不是其他人的另一个聊天).

I have been trying for around 2 days now to get this chat app to work (really basic) that when the one user sends a message, it pops up as a remote notification on the other users screen and when they open it, it must take the second user to the specific chat (with the user that sent the message, not another chat from someone else).

我试图通过打开通知,检查通知来自谁,然后将他们带到相应的聊天中来做到这一点.但是我无法获得 aps 或发送的数据来获取数据.

I am trying to do this by unwrapping the notification, checking who the notification is from, and then taking them to the respective chat. But I cannot get the aps or the sent data to have the data from who it was.

我做了一些研究,其他人的通知看起来像这样:

I have done some research and other peoples notifications look like this:

{
"aps": {
     "badge": 10,
     "alert": "Test",
     "sound": "cat.caf"
},
"url": "http://www.google.com"
}

虽然我的看起来像这样:

While mine looks like this:

{
alert = asd;
}

1) 有没有办法添加更多信息,例如sender idsender name

1) is there a way to add more info such as sender id, sender name, etc.

2) 我怎样才能让它不再作为警报弹出,而是始终将其作为横幅?

2) how can I make this stop popping up as an alert, and rather just always have it as a banner?

推荐答案

所以我设法通过 .setData() 方法做到了.所以这是代码:

So I managed to do it through the .setData() method. So here is the code:

var data: AnyObject = ["from" : "1", "message" : textView.text, "aps" : ["alert" : textView.text, "badge" : "1"]] as NSDictionary
push.setData(data as NSDictionary)

它没有更早工作的原因是因为我试图使用 .setMessage() 以及,如果它在之后覆盖 .setData(),反之亦然.

The reason it was not working earlier was because I was trying to use the .setMessage() as well, which overwrites the .setData() if it comes after, and vice versa.

这篇关于使用推送通知发送数据 - 也不返回整个推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆