使用xmpp和openfire向用户发送好友请求

时间:2014-03-14 06:43:52

标签: ios iphone xmpp openfire xmppframework

你好我已经使用openfire作为服务器并希望发送朋友请求我正在使用以下代码

- (XMPPRoster *)xmppRoster {
    return [[self appDelegate] xmppRoster];
}

-(IBAction)SendFriendRequest:(id)sender
{
    XMPPJID *newBuddy = [XMPPJID jidWithString:@"test1@192.168.4.21"];

    [[[self appDelegate]xmppRoster]addUser:newBuddy withNickname:@"test user 1"];
}

我得到这种类型的日志

<iq xmlns="jabber:client" type="error" to="192.168.4.21/de4fd927"><query xmlns="jabber:iq:roster"><item jid="test1@192.168.4.21" name="test user 3"></item></query><error code="401" type="auth"><not-authorized xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"></not-authorized></error></iq>

我无法向&#34; test1&#34;发送请求已登录火花。

任何帮助都会很明显!

2 个答案:

答案 0 :(得分:1)

  1. 每个可以与其他实体交换XMPP数据包的XMPP实体都应该有username@domain.tld形式的JID,你试图使用IP地址而不是域名,这是可能的,但可能会给出无法预料的错误。

  2. 您应该先在服务器上进行身份验证,然后才能与他人交换数据包。

答案 1 :(得分:1)

似乎你没有在setupStream方法中初始化xmppRoster:

请尝试在设置流中编写以下代码:

xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc] initWithInMemoryStore];

xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:xmppRosterStorage];

xmppRoster.autoFetchRoster = YES;
xmppRoster.autoAcceptKnownPresenceSubscriptionRequests = YES;

[xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()];

[xmppRoster activate:xmppStream];

希望它会给予一些帮助

相关问题