【问题标题】:send friend request to user using xmpp and openfire使用 xmpp 和 openfire 向用户发送好友请求
【发布时间】:2014-04-19 07:51:52
【问题描述】:

您好,我使用 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>

我无法向“test1”发送请求已登录 spark。

任何帮助将不胜感激!

【问题讨论】:

    标签: ios iphone xmpp openfire xmppframework


    【解决方案1】:
    1. 每个可以与其他实体交换 XMPP 数据包的 XMPP 实体都应该有 username@domain.tld 形式的 JID,您尝试使用 IP 地址而不是域名,这是可能的,但可能会给出意外错误。

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

    【讨论】:

      【解决方案2】:

      您似乎没有在 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];
      

      希望能给你一些帮助

      【讨论】:

      • 有什么方法可以将好友请求发送给离线用户?
      • 是的,您可以向离线用户发送好友请求,而在另一端,只要请求的用户在线,就会收到请求。这是代码: XMPPJID *newBuddy = [XMPPJID jidWithString:[NSString stringWithFormat:@"Friendname@YourServer.com"]]; [[self xmppRoster] addUser:newBuddy withNickname:Nil];
      猜你喜欢
      • 1970-01-01
      • 2011-04-30
      • 1970-01-01
      • 2015-04-01
      • 1970-01-01
      • 2015-02-28
      • 2012-08-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多