4

次のコード行を使用して、ユーザーの名簿に新しいバディを追加しようとしています。

XMPPJID jid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@localhost",
                                      addBuddyTextField.text]];
[appDelegate.xmppRoster addUser:jid withNickname:addBuddyTextField.text];

これは機能します。他のユーザーはサブスクリプションリクエスト通知を受け取り、それを受け入れることができ、すべてが正常に機能します。新しいバディがに追加され、 NSArrayXMPPRosterMemoryStorageに表示されるため、現在の名簿とすべてのバディをUIに表示できます。[XMPPRosterMemoryStorage unsortedUsers]

しかし、ユーザーがログアウトしてアプリケーションを再起動すると、彼が追加したすべての仲間とともに、名簿全体が消えます。[XMPPRoster fetchRoster]次のメソッド[XMPPRosterMemoryStorage unsortedUsers]は、アイテムが含まれていないNSArrayを返します。

バディの更新(追加、削除)をXMPPServerに投稿する必要がありますか?または、Rosterは私のXMPPserver(ejabberd)でサポートされていませんか?

XMPPRosterをアクティブ化するために使用するコードは次のとおりです。

xmppRosterMemStorage = [[XMPPRosterMemoryStorage alloc] init];
xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:xmppRosterMemStorage
                                         dispatchQueue:dispatch_get_main_queue()];
[xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()];
xmppRoster.autoAcceptKnownPresenceSubscriptionRequests = false;
xmppRoster.autoFetchRoster = true;
[xmppRoster activate:xmppStream];
[xmppRoster fetchRoster];
4

1 に答える 1

1

上記の説明から、サーバーは名簿リクエストを正常に取得しているようです。セットアップコードを使用すると、発生している問題を再現できません。

ロギングをオンにして、プロトコルログを読み取ることが何が起こっているのかを理解するのに役立つかどうかを確認してみてください。

#import "DDTTYLogger.h"

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    [DDLog addLogger:[DDTTYLogger sharedInstance]];

    ...

または、サーバーでテストコードを試してみて、問題が解決した場合は、そこから作業を開始してください。

#import "AppDelegate.h"
#import "XMPPFramework.h"
#import "DDTTYLogger.h"
#import "DDLog.h"

static const int ddLogLevel = LOG_LEVEL_VERBOSE;

NSString * const XMPPAuthenticationMethodPlain = @"Plain";
NSString * const XMPPAuthenticationMethodDigestMD5 = @"Digest-MD5";

NSString * const OptionHostName = @"...";
NSUInteger const OptionPort = 5222;
BOOL const OptionOldSchoolSSL = NO;
NSString * const OptionJID = @"...";
NSString * const OptionAuthenticationMethod = @"Digest-MD5";
NSString * const OptionPassword = @"...";

@interface AppDelegate () <XMPPStreamDelegate, XMPPRosterMemoryStorageDelegate>

@property (retain) XMPPStream *xmppStream;
@property (retain) XMPPRosterMemoryStorage *xmppRosterMemStorage;
@property (retain) XMPPRoster *xmppRoster;

@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    [DDLog addLogger:[DDTTYLogger sharedInstance]];

    self.xmppStream = [[XMPPStream alloc] init];
    [self.xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
    self.xmppStream.hostName = OptionHostName;
    self.xmppStream.hostPort = OptionPort;
    self.xmppStream.myJID = [XMPPJID jidWithString:OptionJID];

    self.xmppRosterMemStorage = [[XMPPRosterMemoryStorage alloc] init];
    self.xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:self.xmppRosterMemStorage
                                             dispatchQueue:dispatch_get_main_queue()];
    [self.xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()];
    [self.xmppRoster activate:self.xmppStream];

    NSError *error = nil;
    if (OptionOldSchoolSSL)
        [self.xmppStream oldSchoolSecureConnect:&error];
    else
        [self.xmppStream connect:&error];
}

-(void)applicationWillTerminate:(NSNotification *)notification {
    [self.xmppStream removeDelegate:self];
    [self.xmppStream disconnect];
}

-(void)xmppStreamDidConnect:(XMPPStream *)sender {
    Class authClass = nil;
    if ([OptionAuthenticationMethod isEqual:XMPPAuthenticationMethodPlain])
        authClass = [XMPPPlainAuthentication class];
    else if ([OptionAuthenticationMethod isEqual:XMPPAuthenticationMethodDigestMD5])
        authClass = [XMPPDigestMD5Authentication class];
    else {
        DDLogWarn(@"Unrecognized auhthentication method '%@', falling back on Plain",
                  OptionAuthenticationMethod);
        authClass = [XMPPPlainAuthentication class];
    }
    id<XMPPSASLAuthentication> auth = [[authClass alloc] initWithStream:sender
                                                               password:OptionPassword];
    NSError *error = nil;
    if (![sender authenticate:auth error:&error])
        NSLog(@"Error authenticating: %@", error);
}

-(void)xmppRosterDidPopulate:(XMPPRosterMemoryStorage *)sender {
    NSLog(@"users: %@", [sender unsortedUsers]);
    // My subscribed users do print out
}

@end

名簿のセットアップコードをに移動した場合にも機能しますが、その場合-xmppStreamDidAuthenticateは手動で呼び出す必要があり-fetchRosterます。

于 2013-02-02T19:33:13.937 に答える