robbiehanson / XMPPFramework

An XMPP Framework in Objective-C for Mac and iOS
Other
5.91k stars 2.09k forks source link

how to authenticate xmpp stream in ios #707

Open bintu1234 opened 8 years ago

bintu1234 commented 8 years ago

Hi I am working with the xmpp Framework. while I am login i am getting below log

SEND: 2016-04-14 11:35:08:592 [1731:650f] RECV: 2016-04-14 11:35:08:593 [1731:520f] RECV: PLAINANONYMOUSSCRAM-SHA-1CRAM-MD5DIGEST-MD5zlib/stream:features

RECV: PLAINANONYMOUSSCRAM-SHA-1CRAM-MD5DIGEST-MD5zlib/stream:features

RECV: PLAINANONYMOUSSCRAM-SHA-1CRAM-MD5DIGEST-MD5zlib/stream:features

biwsbj05NTczNjM1MjY0LHI9MUMzNjhCODktMjZGNi00NjJFLUJBQTAtNDFCNDA5OEYzMDE4

2016-04-14 11:41:42:545 [1731:622f] RECV: 2016-04-14 11:41:43:177 [1731:622f] RECV: 2016-04-14 11:41:47:547 [1731:607] SEND: biwsbj05NTczNjM1MjY0LHI9REMzRkY3RDQtNEYxNy00RkVBLUE1OTktMjA3QTE5REJGQTNE 2016-04-14 11:41:47:860 [1731:180b] RECV:

if (![xmppStream isDisconnected]) { return YES; } myJID =[NSString stringWithFormat:@"%@@172-31-21-148",[[NSUserDefaults standardUserDefaults] stringForKey:@"userNameJID"]];

NSString *myPassword =@"123456";

// If you don't want to use the Settings view to set the JID, // uncomment the section below to hard code a JID and password. // // myJID = @"user@gmail.com/xmppframework"; // myPassword = @"";

if (myJID == nil || password1 == nil) { return NO; }

[xmppStream setMyJID:[XMPPJID jidWithString:myJID]]; password = myPassword;

NSError *error = nil;

if (![xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&error]) {

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error connecting"
                                                    message:@"See console for error details."
                                                   delegate:nil
                                          cancelButtonTitle:NSLocalizedString( @"O_K", @"OK")
                                          otherButtonTitles:nil];
[alertView show];

DDLogError(@"Error connecting: %@", error);

return NO;

}

return YES;

mouli1102 commented 8 years ago

Check your SSL certificate

bintu1234 commented 8 years ago

@mouli1102 i didn't use any ssl certificate.

Mahipal-credencys commented 8 years ago

Use this funcation before connect

- (void)setupStream
{
    NSAssert(_xmppStream == nil, @"Method setupStream invoked multiple times");

    // Setup xmpp stream
    _xmppStream = [[XMPPStream alloc] init];

#if !TARGET_IPHONE_SIMULATOR
    {
        _xmppStream.enableBackgroundingOnSocket = YES;
    }
#endif

    // Setup reconnect
    _xmppReconnect = [[XMPPReconnect alloc] init];

    // Setup roster
    _xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc] init];

    _xmppRoster = [[XMPPRoster alloc] initWithRosterStorage: _xmppRosterStorage];

    _xmppRoster.autoFetchRoster = YES;
    _xmppRoster.autoAcceptKnownPresenceSubscriptionRequests = YES;

    // Setup vCard support
    _xmppvCardStorage = [XMPPvCardCoreDataStorage sharedInstance];
    _xmppvCardTempModule = [[XMPPvCardTempModule alloc] initWithvCardStorage:_xmppvCardStorage];

    _xmppvCardAvatarModule = [[XMPPvCardAvatarModule alloc] initWithvCardTempModule:_xmppvCardTempModule];

    _xmppCapabilitiesStorage = [XMPPCapabilitiesCoreDataStorage sharedInstance];
    _xmppCapabilities = [[XMPPCapabilities alloc] initWithCapabilitiesStorage:_xmppCapabilitiesStorage];

    _xmppCapabilities.autoFetchHashedCapabilities = YES;
    _xmppCapabilities.autoFetchNonHashedCapabilities = NO;

    [_xmppRoster            activate:_xmppStream];
    [_xmppvCardTempModule   activate:_xmppStream];
    [_xmppvCardAvatarModule activate:_xmppStream];
    [_xmppCapabilities      activate:_xmppStream];

    [_xmppStream setHostName:@"host.credencys.net"];

    [_xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
    [_xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()];

    _allowSelfSignedCertificates = NO;
    _allowSSLHostNameMismatch = NO;

}
mouli1102 commented 8 years ago

@bintu1234 Check your JID and password.

bintu1234 commented 8 years ago

Thanks for the replay suppose my password was changed in openfire server in that case.