XMPPFramework - 用于发送好友请求的XMPPRoster功能?

时间:2013-12-29 19:02:47

标签: ios xmpp xmppframework

我正在尝试实施一个即时消息应用程序,用户可以在其中聊天,并将其他用户添加到他们的名单中并接受好友请求。所以,我已经能够实现聊天,我也能够接收和接受/拒绝朋友请求。

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

- (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中的好友请求?

提前致谢。

2 个答案:

答案 0 :(得分:2)

OP在评论中回答:

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

此代码段将请求发送给其他用户并将其添加到其名册中。

答案 1 :(得分:0)

您可以看到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标志= true:朋友

addToRoster标志= 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;
相关问题