Reputation: 75
I am connecting to XMPP server through XMPPFramework in IOS in objective C, I had initialized the connection parameter in viewDidLoad method like this:
- (void)viewDidLoad {
[super viewDidLoad];
xmppStream = [[XMPPStream alloc] init];
[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
xmppStream.hostName = @"hostname";
xmppStream.hostPort = 5222;
NSString *username = @"[email protected]";
NSString *password = @"123456";
[xmppStream setMyJID:[XMPPJID jidWithString:username]];
NSError *error = nil;
if (![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];
}
}
And Trying to Authenticate in on button click like this:
- (IBAction)connectToXmpp:(id)sender {
NSLog(@"%hhd", [xmppStream isConnected]);
NSError *error = nil;
if (![xmppStream authenticateWithPassword:@"123456" error:&error]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:[NSString stringWithFormat:@"Can't authenticate %@", [error localizedDescription]]
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
}
[xmppStream sendElement:[XMPPPresence presence]];
}
But getting Error message on button click here is the error message:
Can some one please help me.Thanks.
Upvotes: 0
Views: 1006
Reputation: 328
@prem nath
In Above code you are trying to connect to server in - (void)viewDidLoad
.
But You can authenticate with password after server connection established.
So - (void)xmppStreamDidConnect:(XMPPStream *)sender
of XMPPStream Delegate
is called when connection is established. You have to authenticate with server in XMPPStream Delegate.
Upvotes: 2