添加好友代码
初始化xmppStream
_xmppStream = [[XMPPStreamalloc] init];
//[_xmppStream setEnableBackgroundingOnSocket: YES];
[_xmppStreamaddDelegate:selfdelegateQueue:dispatch_get_main_queue()];
//
_xmppRosterDataStorage = [[XMPPRosterCoreDataStoragealloc] init];
_xmppRoster = [[XMPPRosteralloc] initWithRosterStorage:_xmppRosterDataStorage ];
//_xmppRoster.autoFetchRoster = YES;
//_xmppRoster.autoAcceptKnownPresenceSubscriptionRequests = YES;
//}
[_xmppRosteractivate:_xmppStream];
[_xmppRosteraddDelegate:selfdelegateQueue:dispatch_get_main_queue()];
//添加好友
XMPPJID *frendJID = [XMPPJID jidWithString :strFriendJID ];
[_xmppRoster addUser:frendJID withNickname:nick];
//添加后,好友收到消息,好友同意 有如下回调
//收到好友状态
- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence
{
// NSLog(@"presence = %@", presence);
//取得好友状态 subscribed 通过验证好友天骄请求 unsubscribed 对方拒绝
NSString *presenceType = [presence type]; //online/offline
//当前用户
NSString *userId = [[sender myJID] user];
//在线用户
NSString *presenceFromUser = [[presence from] user];
if (![presenceFromUser isEqualToString:userId])
{
//在线状态
if ([presenceType isEqualToString:@"available"])
{
}
else if ([presenceType isEqualToString:@"unavailable"])//离线
{
}
//
}
}