Accept interlocutor request in xmpp client iphone
Ok, I have a great answer for you!
Here is the code:
- (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"]) {
[_chatDelegate newBuddyOnline:[NSString stringWithFormat:@"%@@%@", presenceFromUser, kHostName]];
NSLog(@"presence user wants to subscribe %@",presenceFromUser);
}
}
}
I have provided you with the complete DidReceivePresence method code for your better understanding.
Now let me explain the code to you. If you notice that in the else if clause I am comparing the value (item) we get. So when I get a string like "Subscribe" (when a user sends a request to a friend), you just need to add that particular user to the contact list in the table.
You can get the username from "presenceFromUser".
If you need more understanding then email me at blueobaid@gmail.com because I don't get any alerts when you reply to my answer, although I will come back and reply here to help others too! and I will put a tutorial on http://Czartechnogeeks.com/iSolutions soon
I'm glad I was able to share with the user what is valuable to the user using stackoverflow after helping me a lot.
source to share
You will receive the subscription in the didReceivePresence function .
To accept a subscription, you can use this code:
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];
Let this help :)
source to share