ios, xmpp 친구 추가 및 친구 요청 처리

2464 단어
    XMPPStream *xmppStream;

    XMPPReconnect *xmppReconnect;
    
    XMPPRoster *xmppRoster;// 

// 

    // 
    #pragma mark  
- (void)XMPPAddFriendSubscribe:(NSString *)name
{
  //XMPPHOST  ,     
    XMPPJID *jid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@%@",name,XMPPHOST]];
    //[presence addAttributeWithName:@"subscription" stringValue:@" "];
    [xmppRoster subscribePresenceToUser:jid];
    
}
            // 
          #pragma mark  , 
- (void)xmppRoster:(XMPPRoster *)sender didReceivePresenceSubscriptionRequest:(XMPPPresence *)presence
{
    // 
    NSString *presenceType = [NSString stringWithFormat:@"%@", [presence type]]; //online/offline
    // 
    NSString *presenceFromUser =[NSString stringWithFormat:@"%@", [[presence from] user]];
    NSLog(@"presenceType:%@",presenceType);
    
    NSLog(@"presence2:%@  sender2:%@",presence,sender);
    
    XMPPJID *jid = [XMPPJID jidWithString:presenceFromUser];
    [xmppRoster acceptPresenceSubscriptionRequestFrom:jid andAddToRoster:YES];

}
           // 
#pragma mark  
- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence {
//    DDLogVerbose(@"%@: %@ ^^^ %@", THIS_FILE, THIS_METHOD, [presence fromStr]);
    
    // 
    NSString *presenceType = [NSString stringWithFormat:@"%@", [presence type]]; //online/offline
    // 
//    NSString *userId = [NSString stringWithFormat:@"%@", [[sender myJID] user]];
    // 
    NSString *presenceFromUser =[NSString stringWithFormat:@"%@", [[presence from] user]];
    NSLog(@"presenceType:%@",presenceType);
    NSLog(@" :%@",presenceFromUser);
// 
    if ([presenceType isEqualToString:@"subscribed"]) {
        XMPPJID *jid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@",[presence from]]];
	[xmppRoster acceptPresenceSubscriptionRequestFrom:jid andAddToRoster:YES];
    }
}
#pragma mark  , , 
- (void)removeBuddy:(NSString *)name
{
	XMPPJID *jid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@%@",name,XMPPHOST]];
	
	[self xmppRoster] removeUser:jid];
}
       

좋은 웹페이지 즐겨찾기