Adding user to xmpp room - ios

Hello I know there is alot question regarding this but still i could not figure out what can be the problem. I have sucessfully created group using following code.
- (void)createGroup
{
iXmppEngine.userID = #"lahore123#hassan.local";
iXmppEngine.userPass = #"password123";
self.rosterstorage =[[XMPPRoomCoreDataStorage alloc] init];
XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:self.rosterstorage jid:[XMPPJID jidWithString:#"test#conference.hassan.local"] dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:[[self iXmppEngine]xmppStream]];
[xmppRoom joinRoomUsingNickname:#"Dev iphone" history:nil];
[[[self iXmppEngine] xmppStream] addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[self performSelector:#selector(joinRoom) withObject:nil afterDelay:4];
}
And For adding user i used following code. I have called this function with delay of 5s so room can be created succesfully before adding users.
- (void)joinRoom
{
self.iXmppEngine.userID = #"lahore#hassan.local";
// self.rosterstorage = [[XMPPRoomCoreDataStorage alloc] init];
XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:self.rosterstorage jid:[XMPPJID jidWithString:#"test#conference.hassan.local"] dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:[[self iXmppEngine] xmppStream]];
[xmppRoom joinRoomUsingNickname:#"lahore" history:nil];
[xmppRoom fetchConfigurationForm];
[xmppRoom configureRoomUsingOptions:nil];
[xmppRoom addDelegate:[self iXmppEngine] delegateQueue:dispatch_get_main_queue()];
}
What i am doing wrong couldnt find.

Creating and Joining (Already Created Room or Accepting Invitation To Join Room) Rooms are two differnet scenarios.
// CONFERENCE_ROOM_SERVER is the domain name for MUC
For Creating Group Do This Way:
- (void)createChatRoom:(NSString *) newRoomName
{
XMPPJID *roomJID = [XMPPJID jidWithString:[NSString stringWithFormat:#"%##%#", newRoomName, CONFERENCE_ROOM_SERVER]];
XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];
xmppRoom = [[XMPPRoom alloc]
initWithRoomStorage:roomMemoryStorage
jid:roomJID
dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:[self xmppStream]];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom joinRoomUsingNickname:#"Your Nick Name" history:nil];
}
You will get the response after the group has been created successfully in this delegate:
- (void)xmppRoomDidCreate:(XMPPRoom *)sender
Now Invite Users Here This Way:
[sender inviteUser:[XMPPJID jidWithString:inviteUserJID] withMessage:#"Any Message"];

Related

How to delete or exit from MUC in XMPP

Currently i am making chat application and i required to delete Particular group chat.
For delete group i tried below solution but not working.please check this code
-(void)ExitGroup:(NSString *)Roomjdi Removeuserid:(NSString *)Userid {
{
XMPPJID *roomJID = [XMPPJID jidWithString:Roomjdi];
XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];
XMPPRoom *xmppRooms = [[XMPPRoom alloc]
initWithRoomStorage:roomMemoryStorage
jid:roomJID
dispatchQueue:dispatch_get_main_queue()];
[xmppRooms removeDelegate:self delegateQueue:dispatch_get_main_queue()];
[self deactivate:roomJID];
[self leaveRoom:roomJID];
}
- (void)leaveRoom:(XMPPJID *)myRoomJID
{
// dispatch_block_t block = ^{ #autoreleasepool {
//XMPPLogTrace();
// <presence type='unavailable' to='darkcave#chat.shakespeare.lit/thirdwitch'/>
XMPPPresence *presence = [XMPPPresence presence];
[presence addAttributeWithName:#"to" stringValue:[myRoomJID full]];
[presence addAttributeWithName:#"type" stringValue:#"unavailable"];
[xmppStream sendElement:presence];
[xmppRoom leaveRoom];
[xmppRoom deactivate];
[xmppRoom removeDelegate:self];
}
after i execute this method but in ejabbared display online user in group list.please tell me any where i am wrong.

can't receive group message using xmpp

I can't receive group message on this method.
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
{
NSLog(#"Message received description === %#",[message description]);
}
-(void)sendGroupMessage:(NSString *)NameOfGroup :(NSString *)Msg
{
[xmppRoom sendMessageWithBody:Msg];
NSXMLElement *x = [NSXMLElement elementWithName:NameOfGroup xmlns:XMPPMUCNamespace];
XMPPMessage *message = [XMPPMessage message];
[message addAttributeWithName:#"to" stringValue:[NSString stringWithFormat:#"%#",NameOfGroup]];
[message addChild:x];
NSLog(#"x in Invite === %#",x);
[xmppRoom sendMessage:message];
}
-(void)setUpRoom:(NSString *)ChatRoomJID
{
NSString *Strng=[NSString stringWithFormat:#"Abc#conference.localhost"];
ChatRoomJID=Strng;
XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];
XMPPJID *roomJID = [XMPPJID jidWithString:ChatRoomJID];
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:roomMemoryStorage jid:roomJID dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:xmppStream];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom joinRoomUsingNickname:self.UserID
history:nil
password:nil];
[self performSelector:#selector(ConfigureNewRoom:) withObject:nil afterDelay:4];
}
First of all I create new group, send invitation and successfully accept it also for all invited users.
When I send message on that group, all person got message successfully, But if I will stop App and run again and login with xmpp and send message on group, message is not delivered to joined users.
When i have to log out and login again to xmpp server and send message on previously created group i got this error message
<message xmlns="jabber:client" from="dharmraj123#conference.localhost" to="revoz1wwbzji1e1481005747#localhost/1824017799289652742921131" type="error"><body>1 Message</body><error code="406" type="modify"><not-acceptable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"></not-acceptable><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Only occupants are allowed to send messages to the conference</text></error></message>

Unable to creating room in XAMPPFramework(iOS), getting the error as remote-server-not-found with below code

XMPPJID *roomJID = [XMPPJID jidWithString:#"chat11#conference.local_IP"];
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:roomStorage jid:roomJID dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:[self appDelegate].xmppStream];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom joinRoomUsingNickname:#"pandian"
history:nil password:nil];
any help will be much appreciated.
Check the hostName and port number you have set for the XMPPStream object.
let stream = XMPPStream()
stream.hostName = "hostName"
stream.hostPort = PORT_NUM

Unable to Connect to openfire server, no error or warnings

I a trying to connect to openfire server after following this tutorial and using the xmpp ios code sample.
the code is as follows
- (void)setupStream
{
NSLog(#"Setting up Stream");
xmppStream = [[XMPPStream alloc] init];
[xmppStream setHostName:#"52.0.99.122"];
[xmppStream setHostPort:5222];
NSLog(#"Setup XMPP connection credentials");
#if !TARGET_IPHONE_SIMULATOR
{
xmppStream.enableBackgroundingOnSocket = YES;
}
#endif
xmppReconnect = [[XMPPReconnect alloc] init];
[xmppReconnect activate:xmppStream];
[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
}
I want to know if there is a way to debug or atleast see some error messages.
Thanks.

How to Configure XMPP Facebook chat in iOS application

I am developing an iOS application which uses the Facebook chat feature.
(I am using the XMPPFramework by Robbie Hanson).
https://github.com/robbiehanson/XMPPFramework
In connect method i have given my user name and password
- (BOOL)connect
{
if (![xmppStream isDisconnected]) {
return YES;
}
NSString *myJID = [[NSUserDefaults standardUserDefaults] stringForKey:kXMPPmyJID];
NSString *myPassword = [[NSUserDefaults standardUserDefaults] stringForKey:kXMPPmyPassword];
//
// If you don't want to use the Settings view to set the JID,
// uncomment the section below to hard code a JID and password.
//
myJID = #"example#facebook.com";
myPassword = #"Mypassword";
if (myJID == nil || myPassword == nil) {
return NO;
}
[xmppStream setMyJID:[XMPPJID jidWithString:myJID]];
password = myPassword;
NSError *error = nil;
if (![xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&error])
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error connecting"
message:#"See console for error details."
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alertView show];
DDLogError(#"Error connecting: %#", error);
return NO;
}
in up stream method i have given my host name and port number
- (void)setupStream
{
NSAssert(xmppStream == nil, #"Method setupStream invoked multiple times");
xmppStream = [[XMPPStream alloc] init];
#if !TARGET_IPHONE_SIMULATOR
{
xmppStream.enableBackgroundingOnSocket = YES;
}
#endif
xmppReconnect = [[XMPPReconnect alloc] init];
xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc] init];
xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:xmppRosterStorage];
xmppRoster.autoFetchRoster = YES;
xmppRoster.autoAcceptKnownPresenceSubscriptionRequests = YES;
xmppvCardStorage = [XMPPvCardCoreDataStorage sharedInstance];
xmppvCardTempModule = [[XMPPvCardTempModule alloc] initWithvCardStorage:xmppvCardStorage];
xmppvCardAvatarModule = [[XMPPvCardAvatarModule alloc] initWithvCardTempModule:xmppvCardTempModule];
xmppCapabilitiesStorage = [XMPPCapabilitiesCoreDataStorage sharedInstance];
xmppCapabilities = [[XMPPCapabilities alloc] initWithCapabilitiesStorage:xmppCapabilitiesStorage];
xmppCapabilities.autoFetchHashedCapabilities = YES;
xmppCapabilities.autoFetchNonHashedCapabilities = NO;
// Activate xmpp modules
[xmppReconnect activate:xmppStream];
[xmppRoster activate:xmppStream];
[xmppvCardTempModule activate:xmppStream];
[xmppvCardAvatarModule activate:xmppStream];
[xmppCapabilities activate:xmppStream];
// Add ourself as a delegate to anything we may be interested in
[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppStream setHostName:#"chat.facebook.com"];
[xmppStream setHostPort:5222];
// You may need to alter these settings depending on the server you're connecting to
allowSelfSignedCertificates = NO;
allowSSLHostNameMismatch = NO;
}
Is there any steps that I have missed out? I have no idea how to proceed further. Help me if any one know the solution. Please help me out
Thanks in advance.
Try securing the connection using:
[xmppStream secureConnection:(NSError *)];
in the
- (void)xmppStreamDidConnect:(XMPPStream *)sender;
delegate method.
Hope it helps.

Resources