xmpp からのすべてのメッセージに対して次の xml 形式を取得しています
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
{
NSLog(@"Message %@",message);
}
コンソールでその印刷
<message
xmlns="jabber:client" from="10000006956@xmpp-dev.peeks.com" to="10000006956@xmpp-dev.peeks.com/mobile">
<result
xmlns="urn:xmpp:mam:tmp" id="1483781596098940">
<forwarded
xmlns="urn:xmpp:forward:0">
<message
xmlns="jabber:client" from="10000006931@xmpp-dev.peeks.com/mobile" to="10000006956@xmpp-dev.peeks.com" type="chat">
<body>Hi</body>
<delay
xmlns="urn:xmpp:delay" from="xmpp-dev.peeks.com" stamp="2016-12-22T04:50:17.023Z">Offline Storage
</delay>
</message>
<delay
xmlns="urn:xmpp:delay" from="xmpp-dev.peeks.com" stamp="2017-01-07T09:33:16.099Z">
</delay>
</forwarded>
</result>
</message>
すべてのメッセージから「from」、「to」、「body」、「stamp」を取得したいのですが、次のようにしました
NSXMLElement *body = message;
NSXMLElement *messageb = [body elementForName:@"result" xmlns:@"urn:xmpp:mam:tmp"];
NSXMLElement *forwa=[messageb elementForName:@"forwarded" xmlns:@"urn:xmpp:forward:0"];
NSXMLElement *msg=[forwa elementForName:@"message" xmlns:@"jabber:client"];
NSXMLElement *TD=[forwa elementForName:@"delay" xmlns:@"urn:xmpp:delay"];
NSString *from=[[msg elementForName:@"from" xmlns:@"jabber:client"] stringValue];
NSString *to=[[msg elementForName:@"to" xmlns:@"jabber:client"] stringValue];
NSString *bodyq=[[msg elementForName:@"body"] stringValue];
NSString *stmp=[[TD elementForName:@"stamp" xmlns:@"urn:xmpp:delay"] stringValue];
NSString *final=[NSString stringWithFormat:@"From: %@\nTo: %@\nBody: %@\nStamp: %@",from,to,bodyq,stmp];
NSLog(@"forwa %@", final);
メッセージ本文のみを印刷でき、ログは次のように印刷されます
From: (null)
To: (null)
Body: hi
Stamp: (null)