2014-05-19 40 views
3

我正在開發聊天應用程序我想發送收件人「正在輸入」當我輸入消息時,是否有任何人有想法如何使用xmpp框架來做到這一點,並打開火災作爲服務器。如何使用xmpp openfire發送打字通知

下面

是我的代碼

-(void)sendChatStateNotification: (NSString *)strState 
{ 
    NSXMLElement *message = [NSXMLElement elementWithName:@"message"]; 
    NSXMLElement *chatStatus=[NSXMLElement elementWithName:strState xmlns:xmlns_chatstates]; 
    [message addAttributeWithName:@"type" stringValue:@"chat"]; 
    [message addAttributeWithName:@"to" stringValue:chatWithUser]; 
    [message addChild:chatStatus]; 
} 

-(void)textViewDidChange:(UITextView *)textView 
{ 
    [self sendChatStateNotification:@"composing"]; 
} 

我仍然沒有得到通知

回答

9

要發送打字國家

NSXMLElement *message = [NSXMLElement elementWithName:@"message"]; 
[message addAttributeWithName:@"type" stringValue:@"chat"]; 
[message addAttributeWithName:@"to" stringValue: toID]; 

NSXMLElement *composing = [NSXMLElement elementWithName:@"composing"]; 
[composing addAttributeWithName:@"xmlns" stringValue:@"http://jabber.org/protocol/chatstates"]; 

[message addChild:composing]; 

[xmppStream sendElement:message]; 

接收側

if ([message hasComposingChatState] == YES) 

檢查THI並根據您的打字指示正確使用它。

+2

看看這個擴展類別 - XMPPMessage + XEP_0085 – akc

+0

但更大的挑戰是如何從您設置的標籤 –

+0

中刪除「打字...」,我們可以檢查此狀態? – jaskiratjd