[英]Xmpp MultiUserChat (MUC) Group Does not remain stable
我創建了一個Xmpp聊天應用程序,我已經實現了一對一和群聊。 聊天本身工作正常。 問題出在群聊中。 我創建了一個包含2-3個成員的組,再次聊天工作正常,但是當我殺死應用程序並重新啟動它時,我沒有從我創建的任何組中獲取組的消息。 當我連接到XMPP服務器並重新加入任何組時,我收到消息。 我的問題是,每次我完全殺死應用程序后,我必須再次加入群組。
請讓我知道當我從被殺死狀態打開應用程序時,如何獲取消息或自動加入群組。
一旦應用程序啟動或從后台發出,您需要向XMPP
服務器發送狀態。 所以XMPP
服務器了解相應的group
已准備好處理事件。
編輯 :您可以使用以下代碼發送狀態。
- (void)goOnline {
NSXMLElement *presence = [NSXMLElement elementWithName:@"presence"];
NSXMLElement *show = [NSXMLElement elementWithName:@"show"
stringValue:@"dnd"];
NSXMLElement *status = [NSXMLElement elementWithName:@"status" stringValue:@"available"];
NSXMLElement *priority = [NSXMLElement elementWithName:@"priority" stringValue:@"24"];
[presence addChild:show];
[presence addChild:status];
[presence addChild:priority];
[_xmppStream sendElement:presence];
[self createOrJoinRoom];
}
- (void)createOrJoinRoom {
if ([appDelegate.xmppStream isConnected]) {
NSString *myJID = [[NSUserDefaults standardUserDefaults] stringForKey:@"XMPPUserId"];
NSXMLElement *presence = [NSXMLElement elementWithName:@"presence"];
[presence addAttributeWithName:@"from" stringValue:[[appDelegate.xmppStream myJID]full]];
[presence addAttributeWithName:@"to" stringValue:[NSString stringWithFormat:@"%@@%@/%@", @"newone", GroupChatRoomName,myJID]];
NSXMLElement *xelement = [NSXMLElement elementWithName:@"x" xmlns:XMPPMUCNamespace];
[presence addChild:xelement];
[appDelegate.xmppStream sendElement:presence];
}
}
願這對你有所幫助。
您必須加入以前的所有加入/連接組。 因為在iOS中如果你殺了你的應用程序,那么你就離開了你創建或加入的組。
所以每次都在這段代碼中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
你必須再次加入你的小組。
下面是它的演示代碼:
XMPPRoomHybridStorage *xmppRoomStorage1 = [XMPPRoomHybridStorage sharedInstance];
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:xmppRoomStorage1 jid:RoomName];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom activate:appDelegate.Obj_xmppManager.xmppStream];
NSXMLElement *history = [NSXMLElement elementWithName:@"history"];
[history addAttributeWithName:@"maxstanzas" stringValue:@"1"];
[xmppRoom joinRoomUsingNickname:self.xmppStream.myJID.user history:nil];
除了Presence答案,我還會檢查更基本的東西 -
您創建的房間(群聊)是否持續存在? 或者你每次連接時都要再次創建房間嗎? (注意'開放'和'創造'之間的區別)。
在某些服務器上,默認情況下房間是臨時的 - 您可以通過連接2個單獨的客戶端,發送一些消息,僅斷開其中一個消息並重新連接來檢查這一點 - 如果您確實看到在重新連接的客戶端中發送的消息 - 這可能是您的問題,您可以在創建房間時顯示傳遞給服務器的參數嗎?
您正在使用的服務器是否配置為默認發送歷史消息,如果是這樣,服務器實現的數量可能會有多少,您是否可以在您正在使用的服務器上共享一些信息(openfire,ejabbered,韻律)? 或者您配置文件中的片段?
您是否有可能收到消息,但沒有正確顯示它們,可能在第一次進入房間時沒有刷新屏幕\\視圖? 任何日志消息?
我也面臨這個問題,因為一周后尋找解決方案,經過大量搜索谷歌和堆棧溢出后,我得到了解決這個問題的線索。
在我的情況下,小組成功創建並且聊天工作正常,會員和會員也可以發送給我聊天但是當群組的任何成員退出或殺死應用程序然后再次登錄他無法發送消息時此群組和群組僅在回復時說允許占用者向會議發送消息 。
在我的情況下,當用戶點擊組進入組並開始聊天時,我將此方法稱為加入組。
NSString *roomJID = [NSString stringWithFormat:@"%@@conference.yourHostName", roomJid];
XMPPJID *jid = [XMPPJID jidWithString:roomJID];
_xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:xmppRoomCoreDataStorage jid:jid dispatchQueue:dispatch_get_main_queue()];
[_xmppRoom activate:stream];
[_xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[_xmppRoom joinRoomUsingNickname:stream.myJID.bare history:nil];
希望這也適合你
默認情況下,MUCRoom會向新加入的用戶發送一些歷史記錄,該數字由config在mod_muc: history_size:
下確定。 或者您需要在發送狀態時明確請求一些歷史記錄, doc :
<presence
from='hag66@shakespeare.lit/pda'
id='n13mt3l'
to='coven@chat.shakespeare.lit/thirdwitch'>
<x xmlns='http://jabber.org/protocol/muc'>
<history maxstanzas='20'/>
</x>
</presence>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.