本文介绍了向 ios 发送推送通知以与离线用户 openfire xmpp 聊天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 openfire 的 ios 聊天应用程序,我需要做的是在消息 (1) 由于任何原因无法传递时发送推送通知,(2) 应用程序处于挂起状态,即不能自行生成通知.

I have an ios chat application that uses openfire, what I need to do is send push notification when the message (1) can't be delivered for any reason, (2) app is in suspended state, i.e. can't generate a notification on its own.

我已经在 stackoverflow 和其他地方阅读了大多数相关问题/建议,并且我已经总结出一些解决我的问题的方法.我不是 ios 开发者,几天前我对 openfire 或 xmpp 一无所知,所以我担心我对事情的理解可能不完整,我的解决方案可能有缺陷.

I have read most of the related questions/suggestions on this on stackoverflow and elsewhere and I have concluded few solutions to my problem. I am not an ios developer nor did I know anything about openfire or xmpp before a couple of days, so I am afraid my understanding of things may not be complete and my solutions might be flawed.

请确认我对它的理解,并建议我是否遗漏了什么或者是否有更好的方法.还请说明实施下面列出的特定解决方案的复杂程度.

Kindly confirm my understanding of it and suggest if I am missing something or if there is a better approach. Please also suggest about how complex it is going to be to implement a particular solution listed below.

这里的挑战是确定何时需要推送以及在何处启动流程,因此

Challenge here is to identify when the push is required and where the process be initiated, so

1) 一种方法是使用 xmpp 的 xep-0184 实现来检查消息是否已传递.为此,我们应该在 ios 数据库中有一些带有消息的传递标志,当从另一端接收到传递的响应时,该标志会更新.所以我们需要在一段时间后检查这个标志,如果传递状态为假,则使用消息启动推送过程.看起来是一个复杂的解决方案(等待响应......检查标志有一些时间延迟......不是很令人印象深刻)

1) one way is to use the xep-0184 implementation of xmpp to check if the message is delivered. to do this we should have some delivered flag with message in ios database, which is updated when the delivered response is received form other end. So we need check for this flag after a little while and if the delivered status is false, initiate push process with the message. Looks to be a complicated solution (wait for response.. check flag with some time lag.. not very impressive)

2) 一个更直接的方法是在openfire中做一些事情,当openfire无法传递消息时,它会将它存储在离线表中,我们可以在该部分进行一些拦截并使用该消息启动推送过程.这看起来是正确的方法,但我真的很害怕在 openfire 中得到那么多并改变一些东西(这可能也很容易,用过 openfire 的人可以知道?)

2) A more straight forward approach is to do something in openfire, when openfire can't deliver a message it stores it in offline table, we can do some interception on that part and initiate the push process with the message. This looks to be the correct approach but I am really afraid of getting that much inside openfire and change something(It might be easy also, somebody who has worked a little with openfire can tell?)

3) 这是我最后的手段,这不是解决方案..但如果我不能在预期的时间范围内(从现在起一周)正确完成,我们计划向所有消息.oppenfire 会处理正常的聊天,而我们的服务器会为每条消息发送一个推送,但是当应用程序处于前台时,我们会做一些事情来处理不需要显示的额外推送消息,否则只要有一个推送就会收到信息.你们如何看待这种临时方式(我们当然必须尽快改变它),这是否可行(或者我在这里也遗漏了一些东西).

3) This is my last resort, and this is not a solution.. but if I can't do it correctly within expected timeframe (which is a week from now) , We plan to send a push notification for all the messages. oppenfire will takecare of normal chat while a push will be sent from our server for each message but when the app is in foreground, we do something to handle the extra push messages that need not be shown, otherwise a push is received whenever there is a message. What do you guys think of this temporary way around (we will of course have to change this as soon as we can), is this doable (or I am missing something here as well).

附言谁能告诉 Whatsapp 和其他流行的应用程序如何处理这个问题?

P.S. Can anyone tell how Whatsapp and other popular apps handle this?

非常感谢您的帮助.

推荐答案

XMPP 在整个 XMPP 会话期间需要持久套接字连接或持久"BOSH 连接.我认为您的挑战是 iOS 不允许您在后台运行您的应用程序和套接字.每当您的 iOS 应用程序进入后台时,iOS 都会终止您的套接字连接,并且您的 Openfire 服务器会终止您的 XMPP 会话.这意味着用户离线.这也是该用户的传入消息进入离线存储的原因.

XMPP requires a persistent socket connection or a "persistent" BOSH connection during your whole XMPP session. I think your challenge is that iOS does not allow you to run your app and socket in background. Whenever your iOS app goes in background iOS kills your socket connection, and your Openfire server kills your XMPP session. This means the user goes offline. Which is also the reason why incoming messages for this user go to the offline storage.

对于这个回复很抱歉,但是您建议的所有 3 个解决方案都是可怕的黑客 ;-).如果您想提出一个好的解决方案,您必须深入研究 XMPP 和 iOS.1 周是一个非常短的时间范围.

Sorry for this response, but all 3 solutions you suggested are terrible hacks ;-). If you want to come up with a good solution you have to go very deep into XMPP and iOS. 1 week is a very short timeframe for this.

谁能告诉我们 Whatsapp 和其他流行的应用程序是如何处理这个问题的?

它们使 XMPP 会话保持活动状态.这仅适用于高度修改的 XMPP 服务器,其中一些XMPP 客户端代理"在您的应用处于后台时保持会话运行,或者两者的组合.

They keep the XMPP session alive. This works only with highly modified XMPP servers, some "XMPP Client Proxy" in between which keeps your session running while your app is in background, or a combination or both.

这篇关于向 ios 发送推送通知以与离线用户 openfire xmpp 聊天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 02:55