ios xmppframework没有发送存在
-
21-12-2019 - |
题
我的XMPP流成功连接,在回调中,我尝试发送用户的存在。但是,我继续收到此错误:错误域= xmppstreamerrordomain代码= 1“操作无法完成。(xmppstreamerordomain错误1。)”
我的Connect方法:
- (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];
}
}
.
我的回调:
- (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];
}
.
任何想法?
解决方案
您应该在身份验证完成后发送存在。在此回调中进行:
- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
{
XMPPPresence *presence = [XMPPPresence presence]; // type="available" is implicit
[sender sendElement:presence];
}
. 不隶属于 StackOverflow