Xmpp 接受好友请求 [英] Xmpp Accepting buddy request

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

问题描述

这是我用来发送好友请求的代码,工作正常

This is the code I am using for sending buddy request working fine

XMPPJID *newBuddy = [XMPPJID jidWithString:userName];
[[self appDelegate].xmppRoster addUser:newBuddy withNickname:nil];

这是我用来接受好友请求的代码,工作正常.

This is the code I am using for accepting Buddy request working fine.

XMPPJID *newBuddy = [XMPPJID jidWithString:ipAddress];
     [[self appDelegate].xmppRoster acceptPresenceSubscriptionRequestFrom:newBuddy andAddToRoster:YES];

问题是,每当再次接受请求时,我都会从接受的用户那里获得订阅,这就是问题所在.如何在 xmpp 中停止双向订阅帮助我

Problem is that whenever accepting the request again i am getting subscription from accepted user this is the problem. How to stop two way subscription in xmpp help me

推荐答案

- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence
{
    DDLogVerbose(@"%@: %@ - %@", THIS_FILE, THIS_METHOD, [presence fromStr]);

    NSString *presenceType = [presence type];            // online/offline
    NSString *myUsername = [[sender myJID] user];
    NSString *presenceFromUser = [[presence from] user];
    //
    //new request from unknow user
    if (![presenceFromUser isEqualToString:myUsername])
    {
        if  ([presenceType isEqualToString:@"subscribe"])
        {
            //[_chatDelegate newBuddyOnline:[NSString stringWithFormat:@"%@@%@", presenceFromUser, kHostName]];
            NSLog(@"presence user wants to subscribe %@",presenceFromUser);
            tempPresence = [[XMPPPresence alloc] init];
            tempPresence = presence;
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"New request From:" message:presenceFromUser delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];
            [alert show];
        }
    }
}

<小时>

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    //accept request
    if(buttonIndex==1){
        [xmppRoster subscribePresenceToUser:[tempPresence from]];
    }
}

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

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