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 = @"hostname.com";
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:@"domain.com" 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:@"user@domain.com"];
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];
链接地址: http://www.djcxy.com/p/93528.html

上一篇: 在离线用户的好友请求中缺少元数据

下一篇: iOS的Robbiehanson xmpp框架没有收到聊天消息