Joseph Waelchli Joseph Waelchli - 1 year ago 148
Objective-C Question

Robbiehanson xmpp framework for iOS not receiving chat messages

Trying to create a very simple proof of concept iOS xmpp app with the robbiehanson xmpp frame work, just need to be able to send and receive messages and roster data. I can authenticate and send messages successfully, but when users attempt to respond to my messages I do not receive them. I have implemented the didReceiveMessage delegate method as follows:

-(void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message {
NSLog(@"incoming message: %@", message);

but I never receive this log. If I log in with the existing web app or android app that communicates with this xmpp server I receive these messages, so I'm inclined to believe they are formatted properly. Is there a module I need to add to the XMPPStream for receiving messages? I'm setting up the stream like this (some of the string values have been changed for security and what not):

stream = [[XMPPStream alloc] init];
stream.enableBackgroundingOnSocket = YES;
stream.hostName = @"";
stream.hostPort = 5222;

XMPPRosterCoreDataStorage* xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc] initWithInMemoryStore];
XMPPRoster* xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:xmppRosterStorage];
xmppRoster.autoFetchRoster = YES;
xmppRoster.autoAcceptKnownPresenceSubscriptionRequests = YES;
[stream addDelegate:self delegateQueue:dispatch_get_main_queue()];

XMPPJID* jid = [XMPPJID jidWithUser:@"username" domain:@"" resource:@"iOS"];

[stream setMyJID:jid];

[xmppRoster activate:stream];

[stream connectWithTimeout:XMPPStreamTimeoutNone error:&error]

and then in the xmppStreamDidConnect method I do this to authenticate

NSString *myPassword = @"password";
NSError *error = nil;

[stream authenticateWithPassword:myPassword error:&error]

When I am sending a message out I use this snippet:

MPPJID* recipient = [XMPPJID jidWithString:@""];
XMPPMessage* message = [[XMPPMessage alloc] initWithType:@"chat" to:recipient];
[message addBody:@"hello world"];

[stream sendElement: message];

I'm thinking there is something simple I am missing that someone who has used this before will be able to point out to me right away. I'm ready to supply other info if necessary for solving this issue.


I simply needed to broadcast my presence, then I was able to receive messages.

I added these lines to the streamDidAuthenticate method

XMPPPresence *presence = [XMPPPresence presence];
[sender sendElement:presence];