我成功地能够在我的 iOS XMPP 客户端中接收用户的状态,即状态。但在那个状态中是我希望提取的一些额外信息。此信息在发送时作为子项添加到状态中。
这是我在发送时扩展存在的方式:
- (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];
}
现在,当我收到出席信息时,我想检索出席信息的这个扩展部分。怎么做到呢?
这就是我收到出席信息的方式:
- (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];
}
}
}
}