添加好友代碼
初始化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"])//離線
{
}
//
}
}