ManthanDalal
ManthanDalal

Reputation: 1073

iOS leave user from group chat

I am developing one group chat application in iPhone, in which I want to implement this feature: Admin can remove/kick any participant. And participant must get notification that an admin has removed him from this group.

I have tried below code but without success:

XMPPPresence *presence = [XMPPPresence presenceWithType:@"unavailable"];
[presence addAttributeWithName:@"from" stringValue:[[DatingUserDefaults sharedDefaults] getGroupName]];
[presence addAttributeWithName:@"to" stringValue:[[DatingUserDefaults sharedDefaults] getUsername]];
[xmppStream sendElement:presence]; 

I have searched on Google and got to know that I have to produce the below format in Objective-C:

<presence
    from='[email protected]/pistol'
    to='[email protected]/harfleur'
    type='unavailable'>
  <x xmlns='http://jabber.org/protocol/muc#user'>
    <item affiliation='none' role='none'>
      <actor nick='Fluellen'/>
      <reason>Avaunt, you cullion!</reason>
    </item>
    <status code='307'/>
  </x>
</presence>

Does anyone have any idea about how to do that?

Upvotes: 1

Views: 937

Answers (2)

ToTon
ToTon

Reputation: 1

This work for me

[self.xmppRoom leaveRoom];

Upvotes: 0

Vijay Karthik
Vijay Karthik

Reputation: 467

This works for me.

<iq type="set" to="roomid" id="some random no"><query xmlns="http://jabber.org/protocol/muc#admin"><item affiliation="none" jid="jid you want to remove"></item></query></iq>


NSXMLElement *query = [NSXMLElement elementWithName:@"query" xmlns:@"http://jabber.org/protocol/muc#admin"]; 
NSXMLElement *item = [NSXMLElement elementWithName:@"item"]; 
[item addAttributeWithName:@"affiliation" stringValue:@"none"]; 
[item addAttributeWithName:@"jid" stringValue:"jid to remove"]; 
[query addChild:item]; XMPPIQ *RemoveUser = [[XMPPIQ alloc] initWithType:@"set" to:[XMPPJID jidWithString:roomid] elementID:@"some random id" child:query ]; 
[self.xmppStream sendElement:RemoveUser];

Upvotes: 1

Related Questions