使用XMPP和Openfire向用户发送好友请求

3

你好,我已经使用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>

我无法向已登录Spark的"test1"发送请求。

任何帮助将不胜感激!

2个回答

1
似乎您在setupStream方法中没有初始化xmppRoster:
请尝试在setup stream中编写以下代码:
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];

希望它能提供一些帮助


有没有办法向离线用户发送好友请求? - ios developer
1
是的,您可以向离线用户发送好友请求,另一方面,每当被请求的用户上线时,就会收到该请求。以下是代码:XMPPJID *newBuddy = [XMPPJID jidWithString:[NSString stringWithFormat:@"Friendname@YourServer.com"]]; [[self xmppRoster] addUser:newBuddy withNickname:Nil]; - Gaurav Singla

1
  1. 每个能够与其他实体交换XMPP数据包的XMPP实体,都应该有形如username@domain.tld的JID,你正在尝试使用IP地址而非域名,这是可能的,但可能会导致意外错误。

  2. 在能够与其他人交换数据包之前,您应该在服务器上进行身份验证。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接