如何在XMPP中接受好友请求?

时间:2015-11-09 08:41:05

标签: ios objective-c swift xmpp xmppframework

如何在XMPP中接受传入的好友请求?

此代码可帮助我捕获传入的请求:

public func xmppStream(sender: XMPPStream, didReceivePresence presence: XMPPPresence) {
    print("did received presence : \(presence)")

    if presence.type() == "subscribe" {

    }
}

但在此之后我不知道如何接受这个请求。我搜索了很多,发现这些答案是用ObjectiveC写的:

[self.xmppRoster acceptPresenceSubscriptionRequestFrom:[presence from] andAddToRoster:YES];

另:

XMPPJID *newBuddy = [XMPPJID jidWithString:@"friendsemailid or username"];
[xmppRoster addUser:newBuddy withNickname:nil];

而且:

[xmppRoster subscribePresenceToUser:[tempPresence from]];

但没有人帮助我。在swift中,我无法使用它。没有这样的方法。有帮助吗?我如何接受或拒绝传入的好友请求?

1 个答案:

答案 0 :(得分:0)

如果您使用 robbiehanson XMPPFramework,则可以将其集成到swift项目中并接受以下请求:

let jId = XMPPJID.jidWithString(contact)
xmppRoster!.acceptPresenceSubscriptionRequestFrom(jId, andAddToRoster: true)
相关问题