2

私はejabberdのセットアップに取り組んでおり、サーバーを正常に構成しましたが、クライアント側では、これにXMPPフレームワークが必要です。

私はグーグルで次のリンクを取得しました

http://deusty.blogspot.in/2008/08/xmppframework-on-iphone.html

http://iphone4developer.blogspot.in/2011/07/how-to-add-xmpp-in-your-ios-project.html

robbiehanson / XMPPFrameworkをダウンロードしましたが、エラーが発生し、一部のリンクで404エラーが発生します(削除されました)

このリンク( https://github.com/funkyboy/Building-a-Jabber-client-for-iOS )からjabberクライアントをダウンロードしましたが、xmppフレームワークファイルがアプリからエラー(既に削除されています)をスローします

iPhoneXMPPサンプルのサンプルを1つ取得しましたが、「サーバーに接続できません。xmppStream.hostNameを確認してください」というエラーがスローされます。willSecureWithSettingsメソッドでホスト名を指定しました

疑問:

1)エラーなしで適切なXMPPフレームワークをダウンロードするように案内してください

2)ejabberクライアント側を構成する方法は?

案内してください

よろしくお願いします

4

2 に答える 2

5

このリンクから約 6 か月前に robbiehanson/XMPPFramework をダウンロードしました: https://github.com/robbiehanson/XMPPFramework「はじめに」セクションに記載されている手順に従いました。エラーは発生しませんでした。以下の手順に従って、アプリケーションで xmppframework をセットアップしてみてください。

サンプル アプリでsetupStream()、アプリケーションの起動時に呼び出している関数を見つけました。この関数では、xmppStream を作成し、アプリケーションで必要なさまざまなモジュールをアクティブにしています。例えば

xmppStream = [[XMPPStream alloc] init];

    // Activate xmpp modules after creating them

    [xmppReconnect         activate:xmppStream];
    [xmppRoster            activate:xmppStream];
    [xmppvCardTempModule   activate:xmppStream];
    [xmppvCardAvatarModule activate:xmppStream];
    [xmppCapabilities      activate:xmppStream];

    // Add ourself as a delegate to anything we may be interested in

    [xmppStream addDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];


[xmppStream setHostName:XMPPHOST];
[xmppStream setHostPort:5222];

// You may need to alter these settings depending on the server you're connecting to
allowSelfSignedCertificates = NO;
allowSSLHostNameMismatch = NO;

ストリームを設定したら、次のように認証を行う必要があります。

- (BOOL)connect:(NSString *)myJID    //username registered with server
{
    if (![xmppStream isDisconnected]) {
        return YES;
    }

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

    [xmppStream setMyJID:[XMPPJID jidWithString:myJID]];

    NSError *error = nil;
    if (![xmppStream connect:&error])
    {        
        if(DEBUG)
        {
            NSLog(@"ERROR: Not connected to XMPP Server");
        }
        DDLogError(@"Error connecting: %@", error);
        return NO;
    }
    return YES;
}

この関数はフレームワークによって呼び出され、ここでパスワードを渡します。

- (void)xmppStreamDidConnect:(XMPPStream *)sender
{
    if(sender == xmppStream)
    {
        //DDLogVerbose(@"In xmppStream: %@: %@", THIS_FILE, THIS_METHOD);

        isXmppConnected = YES;

        NSError *error = nil;

        if (![[self xmppStream] authenticateWithPassword:password error:&error])
        {
            DDLogError(@"Error authenticating: %@", error);
        }
    }    
}

ユーザーが認証されると、この関数が呼び出されます。

- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
{
    if(sender == xmppStream)
    {
        [self goOnline];
    }
}

goOnline はユーザーのプレゼンスをサーバーに送信します。

- (void)goOnline
{
    XMPPPresence *presence = [XMPPPresence presence]; // type="available" is implicit
    [xmppStream sendElement:presence];
}

これで、メッセージ/プレゼンスなどを送受信できます。

于 2013-02-28T10:32:03.113 に答える
2

ここに素敵な-完全な-チュートリアルがあります:http://mobile.tutsplus.com/tutorials/iphone/building-a-jabber-client-for-ios-server-setup/

于 2013-03-01T10:14:16.047 に答える