XMPPFramework - 'didReceiveMessage' called two times when message is received - ios

Whenever I receive any new messages, these two methods gets called two times.
- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
I am sending request to server to get my roster list with the following code.
NSXMLElement *query = [NSXMLElement elementWithName:#"query" xmlns:#"jabber:iq:roster"];
XMPPIQ *iq = [XMPPIQ iq];
[iq addAttributeWithName:#"id" stringValue:#"buddyRequest"];
[iq addAttributeWithName:#"to" stringValue:#"54.186.107.171"];
[iq addAttributeWithName:#"type" stringValue:#"get"];
[iq addChild:query];
[self.xmppStream sendElement:iq];
Could somebody point out to me where the problem might lie?
Thank you.

I think you set the delegate to XMPPStream twice.Remove one and check.Then also u got two response , check the xmppstream object value.is both are different , surely you set twice.

Related

Get list of Chat group using XMPPFramework

I am trying to fetch the list of available chat groups in my Ejabbered server with the help of XMPPFramework. Following is my code to fetch the list of Chat Group.
- (void) getChatGroupList{
XMPPJID *servrJID = [XMPPJID jidWithString:#"conference.Server"];
XMPPIQ *iq = [XMPPIQ iqWithType:#"get" to:servrJID];
[iq addAttributeWithName:#"from" stringValue:[[self xmppStream] myJID].full];
NSXMLElement *query = [NSXMLElement elementWithName:#"query"];
[query addAttributeWithName:#"xmlns" stringValue:#"http://jabber.org/protocol/disco#items"];
[iq addChild:query];
[[self xmppStream] sendElement:iq];
}
In response I am getting following XML inside didReceiveIQ
<presence xmlns="jabber:client" from="username#Server/38489493512952747921478847202003609" to="username# Server/38489493512952747921478847202003609"><priority>24</priority><x xmlns="vcard-temp:x:update"><photo/></x><c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="https://github.com/robbiehanson/XMPPFramework" ver="VyOFcFX6+YNmKssVXSBKGFP0BS4="/></presence>
Exact name of the group I can't see in the response. Can anyone help what is missing here or How can I get list of Group name and list of users inside each group?
Have you figure what happened?
From what I see, your request looks OK, but the response should be for other request.
And not sure what version XMPPFramework you are using, in the latest, there is a XMPPMUC class in XEP-0045. You can call discoverRoomsForServiceNamed to do the same stuff. Just make sure to implement XMPPMUCDelegate when you use it.

XMPPMessage time

I'am working with XMPPFramework for iOS and I need to show message's date and time.
After some searching I think that I should use XMPPAutoTime module, but I didn't find some examples.
I used in stream setup:
xmppAutoTime = [[XMPPAutoTime alloc] initWithDispatchQueue:dispatch_get_main_queue()];
[xmppAutoTime activate:self.xmppStream];
My sending message method looks like:
NSXMLElement *message = [NSXMLElement elementWithName:#"message"];
[message addAttributeWithName:#"type" stringValue:#"chat"];
[message addAttributeWithName:#"to" stringValue:to];
[message addChild:[XMPPTime timeElement]];
NSXMLElement *body = [NSXMLElement elementWithName:#"body"];
[body setStringValue:text];
[message addChild:body];
And my XML looks like:
<message type="chat" to="toJID">
<time xmlns="urn:xmpp:time">
<tzo>+03:00</tzo>
<utc>2014-12-30T15:24:22Z</utc>
</time>
<body>message text</body>
</message>
So as you can see I have time in place and it is correct. The question is how I can use it for XMPPMessage
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
I'm working on XMPP too and I'm glad you had this question, as I didn't know how to add time to the messages I send.
Anyway, I'm not sure if there's an easier or a more correct way of doing it, but I use this:
[[message elementForName:#"time"] elementForName:#"utc"]
inside the didReceiveMessage delegate method to extract the time from the XML.

How to integrate XEP-0055 in xmpp Chat app for search user in ios

I am creating a XMPP chat app on iOS. I am trying to do is search user over XMPP. I checked the opernfire server and it has the search plugin enabled. I gone through XEP:0055 and found the stanza.
See http://xmpp.org/extensions/xep-0055.html for reference on the format of the XML you should send and expect to receive back.
If you are trying to perform a search, here is an example for searching for a user by email address
NSString *bareJID = [self.xmppStream.myJID bare];
NSXMLElement *query = [NSXMLElement elementWithName:#"query"];
[query addAttributeWithName:#"xmlns" stringValue:#"jabber:iq:search"];
NSXMLElement *email = [NSXMLElement elementWithName:#"email" stringValue:searchQuery];
[query addChild:email];
NSXMLElement *iq = [NSXMLElement elementWithName:#"iq"];
[iq addAttributeWithName:#"type" stringValue:#"set"];
[iq addAttributeWithName:#"id" stringValue:#"search2"];
[iq addAttributeWithName:#"to" stringValue:[NSString stringWithFormat:#"search.%#",self.xmppStream.myJID.domain]];
[iq addAttributeWithName:#"from" stringValue:bareJID];
[iq addAttributeWithName:#"xml:lang" stringValue:#"en"];
[iq addChild:query];
[self.xmppStream sendElement:iq];
In your callback for xmppStream:didReceiveIQ: you will receive a response from the server, with the same id you specified above (in this case 'search2'). This will be an XML response, as indicated on the initial URL I mentioned for the XEP-0055 reference page, and you can parse it out accordingly.
You can go http://blog.csdn.net/dangfm/article/details/36185879,and follow '搜索关键词' to assemble XML(iq),then _xmppStream send it(iq).

XMPPFramework - How to transfer image from one device to another?

I have made one-to-one chat using XMPP protocol. Now, I would like to send image and video in my application. I researched about the file transfer but I didn't find a solution. I have also used the code below for Socket connection.
Please advice me on how I can go about doing this.
[TURNSocket setProxyCandidates:#[#"MyserverHost-desktop"]];
XMPPJID *jid = [XMPPJID jidWithString:#"1254225445#MyserverHost-desktop"];
TURNSocket *turnSocket = [[TURNSocket alloc] initWithStream:[[self appDelegate]xmppStream] toJID:jid];
[app.turnSocketArray addObject:turnSocket];
[turnSocket startWithDelegate:self delegateQueue:dispatch_get_main_queue()];
[turnSocket release];
- (void)turnSocket:(TURNSocket *)sender didSucceed:(GCDAsyncSocket *)socket
{
}
- (void)turnSocketDidFail:(TURNSocket *)sender
{
}
Every time connection fail method call..
Thanks.
you need push the image to server and you will reveice a url from server .then you can send the url to another device by xmpp protocol. in the end. download the image from server by the received url.
xmpp also can send image . But that's a big xml message for xmpp server .that's not a great solution.
Try this...
NSData *dataF = UIImagePNGRepresentation(SendImage);
NSString *imgStr=[dataF base64Encoding];
NSXMLElement *body = [NSXMLElement elementWithName:#"body"];
[body setStringValue:messageStr];
NSXMLElement *imgAttachement = [NSXMLElement elementWithName:#"attachment"];
[imgAttachement setStringValue:imgStr];
NSXMLElement *message = [NSXMLElement elementWithName:#"message"];
[message addAttributeWithName:#"type" stringValue:#"chat"];
[message addAttributeWithName:#"to" stringValue:chatWithUser];
[message addChild:body];
[message addChild:imgAttachement];
[self.xmppStream sendElement:message];
I hope this will help you...

Message not sent through XMPP

I am using XMPP in my app. My messages are not being sent whenever I attempt to send a message to any specific ID (for example 'test.codemen#gmail.com' in my code).
My code is given below. Thanks in advance.
- (IBAction)sendMsg:(id)sender
{
NSXMLElement *body = [NSXMLElement elementWithName:#"body"];
[body setStringValue:msgField.text];
NSXMLElement *message = [NSXMLElement elementWithName:#"message"];
[message addAttributeWithName:#"type" stringValue:#"chat"];
[message addAttributeWithName:#"to" stringValue:#"test.codemen#gmail.com"];
[message addChild:body];
iPhoneXMPPAppDelegate *share = [iPhoneXMPPAppDelegate sharedInstance];
[[share xmppStream] sendElement:message];
}
your code looks fine to me.
Google Talk routes messages only to contacts you are subscribed to. Is the user you send the message to on your contact list?
Print the xml , then see what's in the message .Maybe you are sending message to a wrong JID .

Resources