iOS XMPPFramework Not Sending Presence
-
21-12-2019 - |
Question
My xmpp stream connects successfully and in the callback I attempt to send out the presence of the user. However, I keep getting this error: Error Domain=XMPPStreamErrorDomain Code=1 "The operation couldn’t be completed. (XMPPStreamErrorDomain error 1.)"
My connect method:
- (void)connect {
NSString *username = @"masa060295@jabber.web.id";
self.password = @"test123";
[self.xmppStream setMyJID:[XMPPJID jidWithString:username]];
NSError *error = nil;
if (![self.xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&error])
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:[NSString stringWithFormat:@"Can't connect to server %@", [error localizedDescription]]
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
}
}
My callback:
- (void)xmppStreamDidConnect:(XMPPStream *)sender {
NSError *error = nil;
NSLog(@"%hhd", [self.xmppStream isConnected]);
if (![self.xmppStream authenticateWithPassword:self.password error:&error]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:[NSString stringWithFormat:@"Can't authenticate %@", [error localizedDescription]]
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
}
XMPPPresence *presence = [XMPPPresence presence];
NSXMLElement *priority = [NSXMLElement elementWithName:@"priority" numberValue:[NSNumber numberWithInt:127]];
[presence addChild:priority];
[self.xmppStream sendElement:presence];
}
Any ideas?
Solution
You should send presence after authentication finished. Do it in this callback:
- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
{
XMPPPresence *presence = [XMPPPresence presence]; // type="available" is implicit
[sender sendElement:presence];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow