iOS XMPP Framework XMPPStream não está conectando?
-
21-12-2019 - |
Pergunta
Estou tentando me conectar a um servidor XMPP público usando o XMPPFramework no iOS.Eu configurei a conexão quando o aplicativo carrega no
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
// Set up XMPP stream
self.xmppStream = [[XMPPStream alloc] init];
[self.xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
self.xmppStream.hostName = @"jabber.web.id";
self.xmppStream.hostPort = 5222;
[self connect];
Em conexão:
- (void)connect {
NSString *username = @"eric1234";
self.password = @"test123";
[self.xmppStream setMyJID:[XMPPJID jidWithString:username]];
NSError *error = nil;
if (![self.xmppStream oldSchoolSecureConnectWithTimeout: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];
}
NSLog(@"%hhd", [self.xmppStream isConnected]);
}
E então meu método delegado:
- (void)xmppStreamDidConnect:(XMPPStream *)sender {
NSError *error = nil;
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];
}
[self.xmppStream sendElement:[XMPPPresence presence]];
}
xmppStreamDidConnect nunca é chamado.Não sei por que registrei eric1234 com sucesso em jabber.web.id usando um cliente XMPP de desktop no servidor.Alguma ideia?
Solução
Eu consertei alterando:
NSString *username = @"eric1234@jabber.web.id";
Outras dicas
9Crie o JID correto:então, no Problema Acima.
NSString *username = @"eric1234@domain_name"; (domain name may be diff. than hostname.)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow