如何在ios中验证xmpp流

时间:2016-04-14 06:17:50

标签: ios iphone xmpp openfire xmppframework

您好我正在使用xmpp Framework。当我登录时,我正在低于日志

SEND: <?xml version='1.0'?>
2016-04-14 11:27:54:712 [1731:1807] SEND: <stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='172-31-21-148'>
 2016-04-14 11:35:08:592 [1731:650f] RECV: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="172-31-21-148" id="58xfmkolyf" stream1:lang="en" version="1.0"/>
 2016-04-14 11:35:08:593 [1731:520f] RECV: <stream:features xmlns:stream="http://etherx.jabber.org/streams"><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>SCRAM-SHA-1</mechanism><mechanism>CRAM-MD5</mechanism><mechanism>DIGEST-MD5</mechanism></mechanisms><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><auth xmlns="http://jabber.org/features/iq-auth"/><register xmlns="http://jabber.org/features/iq-register"/></stream:features>

RECV: <stream:features xmlns:stream="http://etherx.jabber.org/streams"><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>SCRAM-SHA-1</mechanism><mechanism>CRAM-MD5</mechanism><mechanism>DIGEST-MD5</mechanism></mechanisms><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><auth xmlns="http://jabber.org/features/iq-auth"/><register xmlns="http://jabber.org/features/iq-register"/></stream:features>


<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="SCRAM-SHA-1">biwsbj05NTczNjM1MjY0LHI9MUMzNjhCODktMjZGNi00NjJFLUJBQTAtNDFCNDA5OEYzMDE4</auth>
2016-04-14 11:41:42:545 [1731:622f] RECV: <presence xmlns="jabber:client" to="ip-172-31-21-148/58xfmkolyf" type="error"><x xmlns="vcard-temp:x:update"><photo/></x><error code="401" type="auth"><not-authorized xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></presence>
2016-04-14 11:41:43:177 [1731:622f] RECV: <failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>
2016-04-14 11:41:47:547 [1731:607] SEND: <auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="SCRAM-SHA-1">biwsbj05NTczNjM1MjY0LHI9REMzRkY3RDQtNEYxNy00RkVBLUE1OTktMjA3QTE5REJGQTNE</auth>
2016-04-14 11:41:47:860 [1731:180b] RECV: <failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>

在我的连接方法中,我正在做的是

- (BOOL)connect
{

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;

}

但我发送的流JId显示为&#34; 172-31-21-148&#34;但我们需要像username @ servername。我失踪的地方请帮帮我

1 个答案:

答案 0 :(得分:0)

首先,您必须使用以下方法激活XMPP:

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

}

然后通话&#34;连接&#34;方法...