在xmpp客户端iphone中接受好友请求 [英] Accept buddy request in xmpp client iphone

查看:89
本文介绍了在xmpp客户端iphone中接受好友请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iphone开发一个xmpp客户端。我能够发送和接收消息。我想在不提示用户的情况下自动接受好友请求。我将在哪个功能中收到请求。请给我任何提示。

I am developing an xmpp client for iphone. i am able to send and receive message. I want to accept the buddy request automatically without prompting to user. In which function will i receive request. Please give me any hints.

提前致谢。

推荐答案

好的,我有一个完美的答案给你!

Alright, I have got a perfect answer for you!

这是代码:

- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence {

    // a buddy went offline/online

    NSString *presenceType = [presence type];            // online/offline
    NSString *myUsername = [[sender myJID] user];
    NSString *presenceFromUser = [[presence from] user];

    if (![presenceFromUser isEqualToString:myUsername]) {

        if ([presenceType isEqualToString:@"available"]) {

            [_chatDelegate newBuddyOnline:[NSString stringWithFormat:@"%@@%@", presenceFromUser, kHostName]];
               NSLog(@"presence user is %@",presenceFromUser);

        } 

        else if  ([presenceType isEqualToString:@"unavailable"]) {

            [_chatDelegate buddyWentOffline:[NSString stringWithFormat:@"%@@%@", presenceFromUser, kHostName]];
            NSLog(@"presence user is invisible %@",presenceFromUser);

        }
        else if  ([presenceType isEqualToString:@"subscribe"]) {

            [_chatDelegate newBuddyOnline:[NSString stringWithFormat:@"%@@%@", presenceFromUser, kHostName]];
                        NSLog(@"presence user wants to subscribe %@",presenceFromUser);

        }

    }
}

我已经为您提供了完整的DidReceivePresence方法代码,以便您更好地理解。

I have provided you with the complete code of DidReceivePresence method for your better understanding.

现在让我用代码解释一下。如果你注意到else if条件我正在比较我们收到的值(元素)。因此,当我将字符串作为订阅时(当用户发送朋友请求时),您只需要在tableview好友列表中添加该特定用户。

Now let me explain you with the code. If you notice in the else if condition I'm comparing the value (element) which we are receiving. So when I get the string as Subscribe (when the user sends the friend request), you just need to add that particular user in your tableview buddy list.

您可以获得来自presenceFromUser的用户名。

You can get the username from "presenceFromUser".

如果您需要了解更多信息,请发送电子邮件至blueobaid@gmail.com,因为当您回复我的回复时我没有收到提醒,虽然我会回来并在这里回复,以便它也可以帮助别人!我将很快就 http://Czartechnogeeks.com/iSolutions

If you need anymore understanding then email me on blueobaid@gmail.com because I don't get alerts when you response to my answer, though I'll come back and reply here itself so that it might help others too! and I'm going to put a tutorial soon on http://Czartechnogeeks.com/iSolutions

我很高兴能够在帮助我之后用stackoverflow分享对用户有价值的东西。

I'm glad that I'm able to share something valuable to the user with stackoverflow after it helped me much.

这篇关于在xmpp客户端iphone中接受好友请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆