【问题标题】:XMPPFramework - Which XMPPRoster function to use to send a friend request?XMPPFramework - 使用哪个 XMPPRoster 函数来发送好友请求?
【发布时间】:2014-01-16 17:04:24
【问题描述】:

我正在尝试实现一个即时消息应用程序,用户可以在其中聊天以及将其他用户添加到他们的名单中并接受好友请求。因此,到目前为止,我已经能够实现聊天,并且还能够接收和接受/拒绝好友请求。

接受/拒绝订阅请求,代码如下:

- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence
{
    NSString *presenceType = [presence type]; // online / offline
    NSString *myUsername = [[sender myJID] user];
    NSString *presenceFromUser = [[presence from] user];
    NSString *presencefromStr=[presence fromStr];

    if  ([presenceType isEqualToString:@"subscribe"]) {
        if(buttonIndex==1) { // For accept button
            [xmppRoster acceptPresenceSubscriptionRequestFrom:[tmpPresence from] andAddToRoster:YES];
    }
    else { // For reject button
        [xmppRoster rejectPresenceSubscriptionRequestFrom:[tmpPresence from]];
    }
}

但是,现在我遇到了无法发送好友请求的问题。谁能指导我使用 XMPPRoster 的哪个功能?我尝试使用 subscribePresenceToUser 功能,但是没有用。任何帮助将不胜感激。

另外,有人可以判断我使用这种 XMPPRoster 订阅机制的方式是否正确,或者是否有更好的方式来处理 XMPPFramework 中的好友请求?

提前致谢。

【问题讨论】:

  • 各位,我终于可以解决了。这是我想出的代码:XMPPJID *jid = [XMPPJID jidWithString:self.addFriendField.text]; [xmppRoster addUser:jid withNickname:nil]; 此代码 sn-p 将请求发送给其他用户并将他们添加到他们的名册中。

标签: ios xmpp xmppframework


【解决方案1】:

OP 在评论中回答:

XMPPJID *jid = [XMPPJID jidWithString:self.addFriendField.text];
[xmppRoster addUser:jid withNickname:nil];

此代码 sn-p 将请求发送给其他用户并将他们添加到他们的名册中。

【讨论】:

  • 嘿,我试过了,但是没有用。我在 viewController 中声明 XMPPRoster 并在 setupStream 中设置它。但仍然无法正常工作。你能帮我解决这个问题吗
【解决方案2】:

您可以查看XMPPRoster.h 以查看名册扩展中可用的所有功能。

对于您的答案,您有三个选择:

/**
 * Adds the given user to the roster with an optional nickname 
 * and requests permission to receive presence information from them.
**/
- (void)addUser:(XMPPJID *)jid withNickname:(nullable NSString *)optionalName;

/**
 * Adds the given user to the roster with an optional nickname, 
 * adds the given user to groups
 * and requests permission to receive presence information from them.
**/
- (void)addUser:(XMPPJID *)jid withNickname:(nullable NSString *)optionalName groups:(nullable NSArray<NSString*> *)groups;

/**
 * Adds the given user to the roster with an optional nickname,
 * adds the given user to groups
 * and optionally requests permission to receive presence information from them.
**/
- (void)addUser:(XMPPJID *)jid withNickname:(nullable NSString *)optionalName groups:(nullable NSArray<NSString*> *)groups subscribeToPresence:(BOOL)subscribe;

并接受好友请求:(添加为好友、粉丝或拒绝)

addToRoster flag = true : 朋友

addToRoster flag = false : 粉丝

/**
 * Accepts the presence subscription request the given user.
 * 
 * If you also choose, you can add the user to your roster.
 * Doing so is similar to the traditional IM model.
**/
- (void)acceptPresenceSubscriptionRequestFrom:(XMPPJID *)jid andAddToRoster:(BOOL)flag;

/**
 * Rejects the presence subscription request from the given user.
 * 
 * If you are already subscribed to the given user's presence,
 * rejecting they subscription request will not affect your subscription to their presence.
**/
- (void)rejectPresenceSubscriptionRequestFrom:(XMPPJID *)jid;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-19
    • 1970-01-01
    • 1970-01-01
    • 2016-02-23
    • 1970-01-01
    相关资源
    最近更新 更多