gpt4 book ai didi

ios - 如何筛选iOS中收到的XMPP存在?

转载 作者:行者123 更新时间:2023-12-01 18:17:40 24 4
gpt4 key购买 nike

我可以成功接收状态,即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];
}
}
}
}

最佳答案

存在数据包看起来像这样

    //    <presence xmlns="jabber:client" 
// id="Jothb-6"
// from="sender@domain.com/resource"
// to="receiver@domain.com">
// <status>Online</status>
// <show>presence message</show>
// <priority>1</priority>
// </presence>

为了得到这个:
- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence
{
NSXMLElement *showStatus = [presence elementForName:@"status"];
NSString *presenceString = [showStatus stringValue];
NSString *customMessage = [[presence elementForName:@"show"]stringValue];

NSLog(@"Presence : %@, and presenceMessage: %@",presenceString,customMessage);
}

关于ios - 如何筛选iOS中收到的XMPP存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20145107/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com