Message not sent through XMPP - ios

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 .

Related

XMPP remote server connection issue iOS

I am working on a chat application where I set my xmppHostName- 'myserver' and server port -5222. First I created a user on xmpp through my application and it got registered on xmpp but there was an authentication error (although my user id and password were both same). Then I solved this authentication issue by using following method-
NSError *authenticateError = nil;
XMPPPlainAuthentication *plainAuth = [[XMPPPlainAuthentication alloc] initWithStream:self.xmppStream password:password];
if (![_xmppStream authenticate:plainAuth error:&authenticateError]) {
NSLog(#"Authentication errorrrr: %#", authenticateError.localizedDescription);
}
and the authentication error is gone, and my user is online but when I try to send any messages, the server replies with an error through otherserver:
<message xmlns="jabber:client" id="ACC2AAA6-42CE-4590-95A0-C4B28BE9BF04" to="97#otherserver/4ywme5xjh0" from="62#myserver" type="error"><error code="404" type="cancel"><remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></message>
where, 97 is my user id and 62 is front users id. Below is my code for sending xmpp message:
NSXMLElement *body = [NSXMLElement elementWithName:#"body"];
[body setStringValue:messageBody];
NSXMLElement *subject = [NSXMLElement elementWithName:#"subject"];
[subject setStringValue:subjectName];
[message addAttributeWithName:#"to" stringValue:[user stringByAppendingString:myserver]];
[message addChild:body];
[message addChild:subject];
[self.xmppStream sendElement:message];
Here, 'myserver' is my server's hostname and the server replies from another server 'otherserver'. I am sure that I am not setting this 'otherserver' anywhere in my application, then how is this possible that it replies through it?

Send Image by xmppfrmaework

I have set up ejabberd server on localhost, then I registered an account on Adium by selecting XMPP (jabber) server on port 5222. After that I configured an account on mobile test app and sent messages between two users (Adium/test app) successfully. But I am facing an issue(no error messages in console) while sending image from my test app to Adium. It is not received on Adium.
NSData *dataF = UIImageJPEGRepresentation(imageName, 0.0);
NSString *imgStr = [dataF base64EncodedStringWithOptions: 0];
NSXMLElement *body = [NSXMLElement elementWithName:#"body"];
[body setStringValue:#"123"];
NSXMLElement *ImgAttachement = [NSXMLElement elementWithName:#"attachment"];
[ImgAttachement setStringValue: imgStr];
NSXMLElement *message = [NSXMLElement elementWithName:#"message"];
[message addAttributeWithName:#"type" stringValue:#"chat"];
[message addAttributeWithName:#"to" stringValue:jid];
[message addChild:body];
[message addChild:ImgAttachement];
[self.xmppStream sendElement:message];
Any help would be much appreciated.
We saw a similar issue in our ios app. I think you need to somehow add the two users as friends/contacts and make sure you have enabled mod_vcard_xupdate module in ejabberd config file. See if that helps.

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...

Resources