You will receive the subscription in function didReceivePresence.
- (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"]) {
NSXMLElement *presence = [NSXMLElement elementWithName:@"presence"]; [presence addAttributeWithName:@"type" stringValue:@"subscribed"]; [presence addAttributeWithName:@"to" stringValue:[presence fromStr]]; [presence addAttributeWithName:@"from" stringValue:@"you@host"]; [[self xmppStream] sendElement:presence];
} } }
thanks Sumit..
ReplyDeleteThis post is very helpful for me..