I am successfully able to receive presence i.e. status of users in my iOS XMPP client. But within that status is some extra info that I wish to extract. This info was added as a child to the presence while sending.
Here is how I extended presence while sending:
- (void)updatePresence:(NSNotification *)notification
{
XMPPPresence *presence = [XMPPPresence presence];
NSString *string = [notification object]; // object contains some random string.
NSXMLElement *status = [NSXMLElement elementWithName:@"status" stringValue:string];
[presence addChild:status];
NSLog(@"presence info :- %@",presence);
[[self xmppStream] sendElement:presence];
}
Now when I am receiving presence I want to retrieve this extended portion of the presence. How can it be done?
This is how I receive the presence:
- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence
{
NSString *presenceType = [presence type]; // online / offline
NSString *myUsername = [[sender myJID] user];
NSString *presenceFromUser = [[presence from] user];
NSString *presenceString=[presence fromStr];
NSString *string = @"@company.com";
if ([presenceString rangeOfString:string].location == NSNotFound)
{
if (![presenceFromUser isEqualToString:myUsername])
{
if ([presenceType isEqualToString:@"available"])
{
NSMutableDictionary *buddy=[[NSMutableDictionary alloc]init];
[buddy setObject:presenceFromUser forKey:@"name"];
[buddy setObject:[presence fromStr] forKey:@"jid"];
[_chatDelegate newBuddyOnline:buddy];
}
else if ([presenceType isEqualToString:@"unavailable"])
{
NSMutableDictionary *buddy=[[NSMutableDictionary alloc]init];
[buddy setObject:presenceFromUser forKey:@"name"];
[buddy setObject:[presence fromStr] forKey:@"jid"];
[_chatDelegate buddyWentOffline:buddy];
}
}
}
}