Tuesday 12 May 2015

Last online status using XMPP and iOS sdk








If you are using xmpp server for live chat messaging and want to know how to get the last online status of your friend. Then use the following method and you will get the dictionary in xmpp delegates method.
  1. -(void)getlasttimeActivity:(NSString*)userId
  2. {
  3. XMPPJID *touse= [XMPPJID jidWithString:userId];
  4. XMPPIQ *iq = [XMPPIQ iqWithType:@"get" to:touse];
  5. [iq addAttributeWithName:@"id" stringValue:@"last"];
  6. //[iq addAttributeWithName:@"from" stringValue:@"sumeet@app.kinkey.com.au"];
  7. [iq addAttributeWithName:@"from" stringValue:[xmppStream myJID].full];
  8. NSXMLElement *query = [NSXMLElement elementWithName:@"query"];
  9. [query addAttributeWithName:@"xmlns" stringValue:@"jabber:iq:last"];
  10. [iq addChild:query];
  11. NSLog(@"checking IQ==%@",iq);
  12. [xmppStream sendElement:iq];
  13. }
Here you will get the last seen Dictionary
  1. -(BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq
  2. {
  3. NSDictionary *LastseenDict=@{@"userId":[iq from].user,@"lastSeenSec":[[iq childElement] attributeStringValueForName:@"seconds"]};
  4. }

For such more Blogs you can visit to http://findnerd.com/NerdDigest

No comments:

Post a Comment