Question

I'm trying to connect to a public XMPP server using the XMPPFramework on iOS. I set up the connection when the app loads in the

- (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];

In connect:

- (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]);
}

And then my delegate method:

- (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 is never called. I'm not sure why, I've registered eric1234 successfully on jabber.web.id using a desktop XMPP client on the server. Any ideas?

Was it helpful?

Solution

I fixed it by changing:

 NSString *username = @"eric1234@jabber.web.id";

OTHER TIPS

9Create right JID : so, in Above Prob.

NSString *username = @"eric1234@domain_name";     (domain name may be diff. than hostname.)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top