iOS-带有推送通知的聊天应用程序 [英] iOS - Chat application with push notification

查看:92
本文介绍了iOS-带有推送通知的聊天应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单,使用推送通知开发聊天应用程序是个好主意吗?因此,推送通知不可靠,也无法保证它们将到达或不到达。如果不可靠,实时聊天应用应使用哪种技术?

My question is simple, is it a good idea to develop chat application using push notifications? Hence push notifications are not reliable and there is no guaranty either they would arrive or not. If it is not reliable, which technique should be used for real time chat application?

推荐答案

为什么不呢?


使用iOS推送通知建立聊天绝对是可能的。 @Aaron的观点很有趣,但由于以下原因,我认为这没有道理:

Why not?

It's definitely possible to build a chat using iOS push notifications. @Aaron points are interesting, but don't make sense in my opinion for the following reasons:



  1. 如果您的应用程序也发送了许多推送通知(如果您将其用作聊天的手段,则将是),因为它很烦人,没人会使用您的应用。


这里唯一的情况是当应用程序未运行时,即使连续太多,苹果也只会发送最后一条通知。当应用程序处于任何其他状态(背景前台活动和非活动已暂停) ),则可以在推送通知中使用 content-available:1 静默处理通知。如果您为此感到烦恼,只需使用徽章通知而不是警报通知。

The only case here is when the app is not running and even then, apple will only send the last notification if there are too many in a row. When the app is in any other state (background, foreground active & inactive, suspended), the notification can be handled silently, using content-available : 1 in your push notification. If that's a worry for you, simply use badge notifications instead of alert notifications.



  1. 用户还可以禁用应用程序的推送通知,这样您就不能将其作为唯一的通信手段。


错误,这不会阻止通知发送到手机,只是不向用户显示。请参阅此处。因此,即使用户已禁用推送通知,您也可以处理静默通知。这只是一个设置,设备仍将具有设备令牌,后端仍将能够发送推送通知。

That is wrong, that doesn't prevent notifications for being sent to the phone, they are just not being shown to the user. See here. You can therefore handle silent notifications even though the user has disabled push notifications. This is just a setting, the device will still have a device token, and the backend will still be in a position to send push notifications.

确实有些远程通知可能不会传递,并且使用其内容也不是一个好主意。但这不是什么大问题。

It is true that some remote notifications might not be delivered and using their content is not a good idea. But that is not a big issue..

最好是将您的通知用作刷新我收到新消息通知。收到新通知后,请向服务器询问此聊天中的新消息,然后更新表。我们已经在我们的一个项目中实现了这一点,并且到目前为止对结果非常满意。有人说过早的优化是万恶之源,在这种情况下,您可能会花费大量时间使用套接字,但是通过push可以立即启动并运行通知。

The best is to use your notification as a refresh me I got a new message kind of notification. Once you get a new notification, ask the server for new messages in this chat, and update the table. We have implemented this in one of our project and are very happy with the results so far. Some say Premature Optimization is the root of all evil, in that case, you could spend a lot of time using sockets, but you can be up and running in no time with push notifications. Optimize later.

这很有效:

{
    "aps" : {
        "content-available" : 1,
        "alert" : "This is my new notification",
    }
    "conversationId": 23,
    "senderId":44
}

这篇关于iOS-带有推送通知的聊天应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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