i have a lot of search regarding file transfer in IOS. I am using XEP-0065 and XEP-0096 for FileTransfer . Code which i am using :
- (void)sendToOtherDevice:(NSData *)fileData receiverJid:(NSString *)receiverJid
{
NSString *s = [NSString stringWithFormat:#"%#/Smack",receiverJid];
XMPPJID *jid = [XMPPJID jidWithString:s];
// XMPPSIFileTransfer * sifiletransfer = [[XMPPSIFileTransfer alloc] initiateFileTransferTo:jid withData:fileData];
XMPPSIFileTransfer *sifiletransfer = [[XMPPSIFileTransfer alloc] init];
[sifiletransfer initiateFileTransferTo:jid withData:fileData];
//XMPPJID *jid = [XMPPJID jidWithString:receiverJid];
NSString *jabbarID = [[[[self appDelegate] xmppStream] myJID] bare];
XMPPJID *senderjid = [XMPPJID jidWithString:jabbarID];
//[TURNSocket setProxyCandidates:[NSArray arrayWithObjects:s, nil]];
// [TURNSocket setProxyCandidates:[NSArray arrayWithObjects:s,jabbarID, nil]];
[TURNSocket setProxyCandidates:[NSArray arrayWithObjects:jid.domain,senderjid.domain, nil]];
// [TURNSocket setProxyCandidates:[NSArray arrayWithObjects:jid.domain, nil]];
//[TURNSocket setProxyCandidates:[NSArray arrayWithObjects:#"111.11.111.111", nil]];
TURNSocket *socket1 = [[TURNSocket alloc] initWithStream:[self xmppStream] toJID:jid];
// [turnSockets addObject:turnSocket];
[socket1 startWithDelegate:self delegateQueue:dispatch_get_main_queue()];
}
-(void)turnSocket:(TURNSocket *)sender didSucceed:(GCDAsyncSocket *)socket
{
[socket writeData:photoData withTimeout:60.0f tag:0];
[socket disconnectAfterWriting];
}
- (void)turnSocketDidFail:(TURNSocket *)sender
{
NSLog(#"Couldn't set up bytestream for file transfer!");
}
and i found following XML stanzas :
2013-11-22 14:23:08:990 iPhoneXMPP[1434:6417] SEND: <iq type="get" to="lava1" id="A5D91010-C182-4BCB-A989-5DFF2C0B6AE8"><query xmlns="http://jabber.org/protocol/disco#items"/></iq>
2013-11-22 14:23:09:290 iPhoneXMPP[1434:6a07] RECV: <iq xmlns="jabber:client" type="error" id="A5D91010-C182-4BCB-A989-5DFF2C0B6AE8" to="lava#example.com/368c5070" from="lava1"><query xmlns="http://jabber.org/protocol/disco#items"/><error code="404" type="cancel"><remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>
2013-11-22 14:23:09:291 iPhoneXMPP[1434:60b] iPhoneXMPPAppDelegate: xmppStream:didReceiveIQ:
2013-11-22 14:23:09:294 iPhoneXMPP[1434:6417] SEND: <iq type="get" to="example.com" id="7EB43464-63BC-4ADF-8B98-A1A15AB51DB3"><query xmlns="http://jabber.org/protocol/disco#items"/></iq>
2013-11-22 14:23:09:493 iPhoneXMPP[1434:400b] RECV: <iq xmlns="jabber:client" type="result" id="7EB43464-63BC-4ADF-8B98-A1A15AB51DB3" from="example.com" to="lava#example.com/368c5070"><query xmlns="http://jabber.org/protocol/disco#items"><item jid="search.example.com" name="User Search"/><item jid="conference.example.com" name="Public Chatrooms"/><item jid="proxy.example.com" name="Socks 5 Bytestreams Proxy"/><item jid="pubsub.example.com" name="Publish-Subscribe service"/></query></iq>
2013-11-22 14:23:09:494 iPhoneXMPP[1434:60b] iPhoneXMPPAppDelegate: xmppStream:didReceiveIQ:
2013-11-22 14:23:09:504 iPhoneXMPP[1434:6417] SEND: <iq type="get" to="proxy.example.com" id="0DFDF89F-29DE-4477-AF5E-B67387DD973C"><query xmlns="http://jabber.org/protocol/disco#info"/></iq>
2013-11-22 14:23:09:698 iPhoneXMPP[1434:400b] RECV: <iq xmlns="jabber:client" type="result" id="0DFDF89F-29DE-4477-AF5E-B67387DD973C" from="proxy.example.com" to="lava#example.com/368c5070"><query xmlns="http://jabber.org/protocol/disco#info"><identity category="proxy" name="SOCKS5 Bytestreams Service" type="bytestreams"/><feature var="http://jabber.org/protocol/bytestreams"/><feature var="http://jabber.org/protocol/disco#info"/></query></iq>
2013-11-22 14:23:09:699 iPhoneXMPP[1434:60b] iPhoneXMPPAppDelegate: xmppStream:didReceiveIQ:
2013-11-22 14:23:09:701 iPhoneXMPP[1434:6a07] SEND: <iq type="get" to="proxy.example.com" id="63C74776-93A4-4C97-8CFC-63C57494E4F6"><query xmlns="http://jabber.org/protocol/bytestreams"/></iq>
2013-11-22 14:23:09:903 iPhoneXMPP[1434:6417] RECV: <iq xmlns="jabber:client" type="result" id="63C74776-93A4-4C97-8CFC-63C57494E4F6" from="proxy.example.com" to="lava#example.com/368c5070"><query xmlns="http://jabber.org/protocol/bytestreams"><streamhost jid="proxy.example.com" host="10.128.63.123" port="7777"/></query></iq>
2013-11-22 14:23:09:904 iPhoneXMPP[1434:60b] iPhoneXMPPAppDelegate: xmppStream:didReceiveIQ:
2013-11-22 14:23:09:906 iPhoneXMPP[1434:6417] SEND: <iq type="set" to="lava1/Smack" id="BB87F255-51AF-49F1-B700-D009BFF8A057"><query xmlns="http://jabber.org/protocol/bytestreams" sid="BB87F255-51AF-49F1-B700-D009BFF8A057" mode="tcp"><streamhost xmlns="http://jabber.org/protocol/bytestreams" jid="proxy.example.com" host="10.128.63.123" port="7777"/></query></iq>
2013-11-22 14:23:10:210 iPhoneXMPP[1434:6a07] RECV: <iq xmlns="jabber:client" type="error" id="BB87F255-51AF-49F1-B700-D009BFF8A057" to="lava#example.com/368c5070" from="lava1/Smack"><query xmlns="http://jabber.org/protocol/bytestreams" sid="BB87F255-51AF-49F1-B700-D009BFF8A057" mode="tcp"><streamhost jid="proxy.example.com" host="10.128.63.123" port="7777"/></query><error code="404" type="cancel"><remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>
2013-11-22 14:23:10:212 iPhoneXMPP[1434:60b] iPhoneXMPPAppDelegate: xmppStream:didReceiveIQ:
2013-11-22 14:23:10.213 iPhoneXMPP[1434:60b] Couldn't set up bytestream for file transfer!
Please Let me know what i am doing wrong. How Can i use XEP-0096 for FileTransfer.
Related
i am working on XMPP based ios project. i am tring to send message but i am not able to send message. means receiver will not receive the message.
here is my code.
- (IBAction)sendMessageNow:(id)sender
{
NSString *messageStr =messageField.text;
if([messageStr length] > 0)
{
NSLog(#"Message sending fron Gmail");
NSXMLElement *body = [NSXMLElement elementWithName:#"body"];
[body setStringValue:messageStr];
NSXMLElement *message = [NSXMLElement elementWithName:#"message"];
[message addAttributeWithName:#"type" stringValue:#"chat"];
[message addAttributeWithName:#"to" stringValue:#"destination address"];
[message addChild:body];
NSLog(#"message1%#",message);
[[self appDelegate].xmppStream sendElement:message];
}
NSDate *date = [NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"hh:mm a"];
//[self sendMessage];
if ([self.messageField.text length]>0) {
if (isfromMe)
{
NSString *rowNum=[NSString stringWithFormat:#"%d",(int)sphBubbledata.count];
[self adddMediaBubbledata:kTextByme mediaPath:self.messageField.text mtime:[formatter stringFromDate:date] thumb:#"" downloadstatus:#"" sendingStatus:kSending msg_ID:[self genRandStringLength:7]];
[self performSelector:#selector(messageSent:) withObject:rowNum afterDelay:1];
isfromMe=NO;
}
else
{
[self adddMediaBubbledata:kTextByOther mediaPath:self.messageField.text mtime:[formatter stringFromDate:date] thumb:#"" downloadstatus:#"" sendingStatus:kSent msg_ID:[self genRandStringLength:7]];
isfromMe=YES;
}
self.messageField.text=#"";
[self.chattable reloadData];
[self scrollTableview];
}
}
and here is my senderdidreceivemessage method from appdelegate.m
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
{
DDLogVerbose(#"%#: %#", THIS_FILE, THIS_METHOD);
[[self xmppStream] sendElement:message];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertAction = #"OK";
localNotification.fireDate = [NSDate date];
// localNotification.alertBody = xmppmessage;
localNotification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
// A simple example of inbound message handling.
if ([message isChatMessageWithBody])
{
XMPPUserCoreDataStorageObject *user = [xmppRosterStorage userForJID:[message from]
xmppStream:xmppStream
managedObjectContext:[self managedObjectContext_roster]];
NSString *body = [[message elementForName:#"body"] stringValue];
NSString *displayName = [user displayName];
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:displayName
message:body
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alertView show];
}
else
{
// We are not active, so use a local notification instead
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertAction = #"Ok";
localNotification.alertBody = [NSString stringWithFormat:#"From: %#\n\n%#",displayName,body];
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
}
}
}
EDIT
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *L_CellIdentifier = #"SPHTextBubbleCell";
static NSString *R_CellIdentifier = #"SPHMediaBubbleCell";
SPH_PARAM_List *feed_data=[[SPH_PARAM_List alloc]init];
feed_data=[sphBubbledata objectAtIndex:indexPath.row];
if ([feed_data.chat_media_type isEqualToString:kTextByme]||[feed_data.chat_media_type isEqualToString:kTextByOther])
{
SPHTextBubbleCell *cell = (SPHTextBubbleCell *) [tableView dequeueReusableCellWithIdentifier:L_CellIdentifier];
if (cell == nil)
{
cell = [[SPHTextBubbleCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:L_CellIdentifier];
}
XMPPUserCoreDataStorageObject *user = [[self fetchedResultsController] objectAtIndexPath:indexPath];
//cell.textLabel.text = user.displayName;
//[self configurePhotoForCell:cell user:user];
cell.bubbletype=([feed_data.chat_media_type isEqualToString:kTextByme])?#"LEFT":#"RIGHT";
cell.textLabel.text = user.displayName;
cell.textLabel.tag=indexPath.row;
cell.timestampLabel.text = #"02:20 AM";
cell.CustomDelegate=self;
cell.AvatarImageView.image=([feed_data.chat_media_type isEqualToString:kTextByme])?[UIImage imageNamed:#"ProfilePic"]:[UIImage imageNamed:#"person"];
// cell.AvatarImageView.image=[
[self configurePhotoForCell:cell user:user] ;
return cell;
}
SPHMediaBubbleCell *cell = (SPHMediaBubbleCell *) [tableView dequeueReusableCellWithIdentifier:R_CellIdentifier];
if (cell == nil)
{
cell = [[SPHMediaBubbleCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:R_CellIdentifier];
}
cell.bubbletype=([feed_data.chat_media_type isEqualToString:kImagebyme])?#"LEFT":#"RIGHT";
cell.textLabel.text = feed_data.chat_message;
cell.messageImageView.tag=indexPath.row;
cell.CustomDelegate=self;
cell.timestampLabel.text = #"02:20 AM";
cell.AvatarImageView.image=([feed_data.chat_media_type isEqualToString:kImagebyme])?[UIImage imageNamed:#"ProfilePic"]:[UIImage imageNamed:#"person"];
return cell;
}
and configure photo method
- (void)configurePhotoForCell:(UITableViewCell *)cell user:(XMPPUserCoreDataStorageObject *)user
{
// Our xmppRosterStorage will cache photos as they arrive from the xmppvCardAvatarModule.
// We only need to ask the avatar module for a photo, if the roster doesn't have it.
if (user.photo != nil)
{
cell.imageView.image = user.photo;
}
else
{
NSData *photoData = [[[self appDelegate] xmppvCardAvatarModule] photoDataForJID:user.jid];
if (photoData != nil)
cell.imageView.image = [UIImage imageWithData:photoData];
else
cell.imageView.image = [UIImage imageNamed:#"user2"];
}
}
EDIT
Both are send by me but it looks in same window, when i click on one time send button it looks in sender message and second time looks in receiver message. and receiver will not receive message.
EDIT
Here is response after i click on send button.
function:-[ChathistryViewController sendMessageNow:] line:414 content:Message sending fron Gmail
function:-[ChathistryViewController sendMessageNow:] line:421 content:message1ghfhxfghh
2015-06-12 13:03:22:071 projectname[7556:2f03] SEND: ghfhxfghh
2015-06-12 13:03:22:389 projectname[7556:7347] RECV: ghfhxfghh
2015-06-12 13:03:22:390 CloseChat[7556:2f03] SEND: ghfhxfghh
2015-06-12 13:03:22.393 projectname[7556:49110] Attempting to schedule a local notification {fire date = (null), time zone = (null), repeat interval = 0, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Friday, June 12, 2015 at 1:03:22 PM India Standard Time, user info = (null)} with a sound but haven't received permission from the user to play sounds
2015-06-12 13:03:22:697 CloseChat[7556:7347] RECV:
2015-06-12 13:03:23:004 projectname[7556:7347] SEND:
2015-06-12 13:03:23:004 projectname[7556:7347] SEND: http://etherx.jabber.org/streams' version='1.0' to='jwchat.org'>
2015-06-12 13:03:23:619 projectname[7556:7347] RECV:
2015-06-12 13:03:23:619 projectname[7556:7347] RECV:
2015-06-12 13:03:23:619 CloseChat[7556:7347] SEND:
2015-06-12 13:03:23:925 projectname[7556:7347] RECV:
2015-06-12 13:03:23:926 projectname[7556:7347] SEND: http://etherx.jabber.org/streams' version='1.0' to='jwchat.org'>
2015-06-12 13:03:25:063 projectname[7556:7627] RECV:
2015-06-12 13:03:25:064 projectname[7556:7347] RECV: PLAINDIGEST-MD5SCRAM-SHA-1
2015-06-12 13:03:25:065 CloseChat[7556:607] SEND: biwsbj1jaGlyYWcscj1EMjUxMEQ2NC05MzZFLTQxMkUtQjY1Ri0zM0VFQjE1ODcxRjc=
2015-06-12 13:03:25:306 projectname[7556:7347] RECV: cj1EMjUxMEQ2NC05MzZFLTQxMkUtQjY1Ri0zM0VFQjE1ODcxRjdXVnB5eEp3b2lCRC9rUThvRkdhbGdRPT0scz1DZVZpSFFXNW9XRDVVNU90WUNMWExnPT0saT00MDk2
2015-06-12 13:03:25:321 projectname[7556:7347] SEND: Yz1iaXdzLHI9RDI1MTBENjQtOTM2RS00MTJFLUI2NUYtMzNFRUIxNTg3MUY3V1ZweXhKd29pQkQva1E4b0ZHYWxnUT09LHA9TWlsaW5TczI4b2VBd1dtQ3pWY21TWXZQWEFnPQ==
2015-06-12 13:03:25:562 projectname[7556:7627] RECV: dj1WeVdSaWRTTHVxYzhkV0E2aEg3OW9mU0FpYmc9
2015-06-12 13:03:25:562 projectname[7556:7627] SEND: http://etherx.jabber.org/streams' version='1.0' to='jwchat.org'>
2015-06-12 13:03:25:871 projectname[7556:7627] RECV:
2015-06-12 13:03:25:871 projectname[7556:7627] RECV:
2015-06-12 13:03:25:872 projectname[7556:7627] SEND:
2015-06-12 13:03:26:178 projectname[7556:7347] RECV: chirag#jwchat.org/341204969114349440629043
2015-06-12 13:03:26:179 projectname[7556:7347] SEND:
2015-06-12 13:03:26:485 projectname[7556:7347] RECV:
2015-06-12 13:03:26:486 projectname[7556:7627] SEND:
2015-06-12 13:03:26:487 projectname[7556:7347] SEND:
2015-06-12 13:03:26:488 projectname[7556:7627] SEND:
2015-06-12 13:03:26:714 projectname[7556:7347] RECV:
2015-06-12 13:03:26:946 projectname[7556:7347] RECV:
2015-06-12 13:03:26:947 projectname[7556:6e13] SEND:
2015-06-12 13:03:26:948 projectname[7556:6e13] RECV:
2015-06-12 13:03:27:180 projectname[7556:7627] RECV:
You must make sure first that your XMMP client is set up correctly. Then make sure that you are sending the message, and that you have the right sender.
For those who will now say that this is a comment, not an answer, I don't have enough reputation to comment!
The Control is just for UI purpose, I never wrote any code to send or receive a message from the server because I m not sure whether a user will use any third party SDK or XMPP or normal REST API.
So, you make the Server part & UI part separately.
Your question :
Both are sent by me but it looks in the same window when I click on one-time send button it looks in sender message and second time looks in receiver message. and receiver will not receive a message.
Ans: Yes, I have done that for Demo purpose, based on the response you will get from server you have to make the changes in code.
How to use:
1. Declare an NsmutableArray & initialize it on viewdidload.
2. When you send an Message, image, create a Bubbledata & add it to the array & then reload the Tableview.
[self adddMediaBubbledata:kTextByme mediaPath:#"Hi, check this new control!"
mtime:#"8:30 AM" thumb:#"NA" downloadstatus:#"" sendingStatus:kSent msg_ID:#"AB4353GH"];
Use Below types for send and receive:
kTextByme: if you sending a text
kImageByme : if you are sending an Image
kTextByOther : if you receiving an Text
kImageByOther : if you are receiving an Image
Now update the send Status
kSent : you successfully sent an message
kFailed : message sendig failed
kSending : your message is sending to server
So , based on the above information , make the changes and let me know if you require any other help
Please locate below delegate in XMPP Client(XMMPFramework), it will handle the received instant messages to you.
// XMPP Delegate method: xmpp client receives a message
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
{
// some computation stuff
return ;
}
I am trying to implement XEP-0055 which is supported by ejabbed as shown here in supported xeps
This is my request:
XMPPIQ *iq = [[XMPPIQ alloc] init];
[iq addAttributeWithName:#"type" stringValue:#"get"];
[iq addAttributeWithName:#"from" stringValue:#"testuser1#company.com"];
[iq addAttributeWithName:#"to" stringValue:#"company.com"];
[iq addAttributeWithName:#"id" stringValue:#"search1"];
XMPPElement *query = [XMPPElement elementWithName:#"query"];
[query setXmlns:#"jabber:iq:search"];
[iq addChild:query];
[self.xmppStream sendElement:iq];
I am getting this response:
<iq xmlns="jabber:client" from="company.com" to="testuser1#company.com/2834146151141475281662718" type="error" id="search1">
<query xmlns="jabber:iq:search"/>
<error code="501" type="cancel">
<feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
</error>
</iq>
Why am I receiving feature-not-implemented? Link to official XEP description.
In ejabberd, the search functionality is delegated to a subdomain, by default using the vjud prefix. Try sending the search request to vjud.company.com instead.
All one-one chat is send with Message Type as Chat.
Thus the Message Archiving technique (shown below) worked fine for me to save/retrieve chat history.
// Setup message archiving
xmppMessageArchivingStorage = [XMPPMessageArchivingCoreDataStorage sharedInstance];
xmppMessageArchiving = [[XMPPMessageArchiving alloc] initWithMessageArchivingStorage:xmppMessageArchivingStorage];
[xmppMessageArchiving setClientSideMessageArchivingOnly:YES];
// Activate xmpp modules
[xmppMessageArchiving activate:xmppStream];
// Add delegate
[xmppMessageArchiving addDelegate:self delegateQueue:dispatch_get_main_queue()];
However for Group Chat, the message type sent is "groupchat"
This will not be archived by the XMPPMessageArchivingCoreDataStorage
Can someone please guide me as to how I can achieve the Message Archiving for Group Chat Message.
This is the Series of Stanza that you will need to send to get Archived Messages. For more detail you can checkout http://xmpp.org/extensions/xep-0136.html
REQ
<iq type='get' id='mrug_sender#staging.openfire.com'>
<list xmlns='urn:xmpp:archive'
with='mrug_target_155#staging.openfire.com'>
<set xmlns='http://jabber.org/protocol/rsm'>
<max>6900</max>
</set>
</list>
</iq>
RES
<iq type="result" id="mrug_sender#staging.openfire.com" to="mrug_sender#staging.openfire.com/Psi">
<list xmlns="urn:xmpp:archive">
<chat with="mrug_target_155#staging.openfire.com" start="2014-06-07T06:52:26.041Z"/>
<chat with="mrug_target_155#staging.openfire.com" start="2014-06-07T07:06:53.372Z"/>
<set xmlns="http://jabber.org/protocol/rsm">
<first index="0">866</first>
<last>867</last>
<count>2</count>
</set>
</list>
</iq>
REQ
<iq type='get' id='mrug_sender#staging.openfire.com'>
<retrieve xmlns='urn:xmpp:archive' with='mrug_target_155#staging.openfire.com' start='2014-06-07T06:52:26.041Z'>
<set xmlns='http://jabber.org/protocol/rsm'>
<max>8000</max>
</set>
</retrieve>
</iq>
RES
<iq type="result" id="mrug_sender#staging.openfire.com" to="mrug_sender#staging.openfire.com/Psi">
<chat xmlns="urn:xmpp:archive" with="mrug_target_155#staging.openfire.com" start="2014-06-07T06:52:26.041Z">
<from secs="0" jid="mrug_target_155#staging.openfire.com">
<body>Wow !! This is Archived Message</body>
</from>
<set xmlns="http://jabber.org/protocol/rsm">
<first index="0">0</first>
<last>0</last>
<count>1</count>
</set>
</chat>
</iq>
To Fetch List of all Conversations
<iq type='get' id='mrug_sender#staging.openfire.com'>
<list xmlns='urn:xmpp:archive'>
<set xmlns='http://jabber.org/protocol/rsm'>
<max>6900</max>
</set>
</list>
</iq>
You can easily get archive messages from xmpp core database. Use Below code.
XMPPMessageArchivingCoreDataStorage *_xmppMsgStorage = [XMPPMessageArchivingCoreDataStorage sharedInstance];
NSManagedObjectContext *moc = [_xmppMsgStorage mainThreadManagedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:#"XMPPMessageArchiving_Message_CoreDataObject"
inManagedObjectContext:moc];
NSFetchRequest *request = [[NSFetchRequest alloc]init];
[request setEntity:entityDescription];
//[request setFetchLimit:20];
NSError *error;
NSString *predicateFrmt = #"bareJidStr == %#";
NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateFrmt, [NSString stringWithFormat:#"%#%#",GroupName,GROUP_CHAT_DOMAIN]];
request.predicate = predicate;
NSArray *messages = [moc executeFetchRequest:request error:&error];
I am developing a chat system in both iOS. The chat server which I am using is ejabbered server. I am using Robbiehanson xmppframework for iOS chat client.
The issue which I am facing is that I am not able to establish a proper xmppstream between the chat client and the server. The xmppstream state is in STATE_XMPP_REGISTERING. This holds a value of 8. Due to this,when I try to authenticate the just created registered user, I am encountering an exception
"Error authenticating: Error Domain=XMPPStreamErrorDomain Code=1 "Please wait until the stream is connected." UserInfo=0x166c1e30 {NSLocalizedDescription=Please wait until the stream is connected.}
But surprisingly, I am able to register a user using a password. When I try to authenticate the user, I am encountering this exception due to which the registered user is not able to appear ONLINE.
I am using ConnectWithTimeOut to connect the xmppstream to the server
NSString *myPassword = #"password";
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;
}
Using this above code, I am able to establish a connection to the server.
Once the connectton is established, xmppStreamDidConnect is invoked.
when I checked the status of the XMPPStream, I am seeing the stream is connected.
Below is the code.
- (void)xmppStreamDidConnect:(XMPPStream *)sender
{
if ([xmppStream isDisconnected]){
NSLog(#"Is DisConnected");
[self connect];
}
if ([xmppStream isConnecting]){
NSLog(#"Is Connecting");
}
if ([xmppStream isConnecting]){
NSLog(#"Is Connecting");
}
if ([xmppStream isConnected]){
NSLog(#"Is Connected");
}
NSError *error = nil;
if (![[self xmppStream] registerWithPassword:#"password" error:&error]) {
NSLog(#"Registration error: %#", error);
}
if (![[self xmppStream] authenticateWithPassword:password error:&error])
{
DDLogError(#"Error authenticating: %#", error);
}else{
[self goOnline];
XMPPPresence *presence = [XMPPPresence presenceWithType:#"available"];
[sender sendElement:presence];
}
As per the above code, a user is registered and here comes the issue. When I try to authenticate the user, using authenticateWithPassword:password
XMPPLogTrace();
// The given password parameter could be mutable
NSString *password = [inPassword copy];
__block BOOL result = YES;
__block NSError *err = nil;
dispatch_block_t block = ^{ #autoreleasepool {
if (state != STATE_XMPP_CONNECTED)
{
NSString *errMsg = #"Please wait until the stream is connected.";
NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
err = [NSError errorWithDomain:XMPPStreamErrorDomain code:XMPPStreamInvalidState userInfo:info];
result = NO;
return_from_block;
}
if (myJID_setByClient == nil)
{
NSString *errMsg = #"You must set myJID before calling authenticate:error:.";
NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
err = [NSError errorWithDomain:XMPPStreamErrorDomain code:XMPPStreamInvalidProperty userInfo:info];
result = NO;
return_from_block;
}
the code below gets executed. But when I check the status of the xmppstream when I enter this delegate, I am seeing it in status 8 (which is STATE_XMPP_REGISTERING) though the user is successfully registered. This status makes to return a NO and hence the registered user is not appearing online.
Could anyone please help me in resolving this issue. I tried a lot of ways. But not able to progress.
Why I am not able to move to the next status and ultimately to status 12 before the authenticatewithpassword is invoked. Am I missing any intermediate steps after establishing a connection and successful registration. In nutshell, why the stream state stops at 8. and not going forward to
STATE_XMPP_AUTH,STATE_XMPP_BINDING,STATE_XMPP_START_SESSION, STATE_XMPP_CONNECTED, before getting into authenticatewithpassword
Logs for more info.
2014-05-30 07:40:20:995 konnectlinks[3249:8403] SEND: <?xml version='1.0'?>
2014-05-30 07:40:20:996 konnectlinks[3249:8403] SEND: <stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='localhost'>
2014-05-30 07:40:21.246 konnectlinks[3249:60b] dhaval is here
2014-05-30 07:40:21:608 konnectlinks[3249:4717] RECV: <stream:stream xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" id="114321716" from="localhost" version="1.0" stream1:lang="en"/>
2014-05-30 07:40:21:609 konnectlinks[3249:8403] RECV: <stream:features xmlns:stream="http://etherx.jabber.org/streams"><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>SCRAM-SHA-1</mechanism><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism></mechanisms><c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://www.process-one.net/en/ejabberd/" ver="9DVbXp9C/vTyB5mLfy7wktk5Pfs="/><register xmlns="http://jabber.org/features/iq-register"/></stream:features>
2014-05-30 07:40:21.610 konnectlinks[3249:8403] -[XMPPReconnect xmppStreamDidConnect:]
2014-05-30 07:41:01.558 konnectlinks[3249:60b] Is Connected
2014-05-30 07:41:01.561 konnectlinks[3249:8403] -[XMPPReconnect setMultipleReachabilityChanges:]
2014-05-30 07:41:14.073 konnectlinks[3249:8403] -[XMPPReconnect setManuallyStarted:]
2014-05-30 07:41:14.076 konnectlinks[3249:8403] -[XMPPReconnect teardownReconnectTimer]
2014-05-30 07:41:14:076 konnectlinks[3249:60b] SEND: <iq type="set"><query xmlns="jabber:iq:register"><username>timop</username><password>password</password></query></iq>
2014-05-30 07:41:14.077 konnectlinks[3249:8403] -[XMPPReconnect teardownNetworkMonitoring]
2014-05-30 07:42:07:428 konnectlinks[3249:860b] RECV: <iq xmlns="jabber:client" from="localhost" type="result"><query xmlns="jabber:iq:register"><username>timop</username><password>password</password></query></iq>
2014-05-30 07:42:10:312 konnectlinks[3249:60b] Error authenticating: Error Domain=XMPPStreamErrorDomain Code=1 "Please wait until the stream is connected." UserInfo=0x166c1e30 {NSLocalizedDescription=Please wait until the stream is connected.}
I am sure someone would have encountered the issue.
Please help me in resolving this issue. Advance thanks for your time and help
I reviewed the code seems its right , Make sure the username and password you send it must be correct.
If nothing goes right then contact with your server/web team regarding this or try to connect with creating new user
I have created a MembersOnly, Persistant Room. In which I have invited multiple occupants.
Now I want to fetch detail of room for the user which was invited by creator.
I tried this code :
XMPP requirement :
<iq from='hag66#shakespeare.lit/pda'
id='ik3vs715'
to='coven#chat.shakespeare.lit'
type='get'>
<query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>
iOS code to call the from iOS
NSXMLElement *query = [NSXMLElement elementWithName:#"query" xmlns:#"http://jabber.org/protocol/disco#info"];//
NSString *iqID = [[appDelegate xmppStream] generateUUID];
XMPPJID *jID = self.room.roomJID;
XMPPIQ *element = [XMPPIQ iqWithType:#"get" to:jID elementID:iqID child:query];
[element addAttributeWithName:#"from" stringValue:[[[appDelegate xmppStream] myJID] full]];
[[appDelegate xmppStream] fetchInformationForGivenIQ:element];
This should provide me this kinda result :
<iq from='coven#chat.shakespeare.lit'
id='ik3vs715'
to='hag66#shakespeare.lit/pda'
type='result'>
<query xmlns='http://jabber.org/protocol/disco#info'>
<identity
category='conference'
name='A Dark Cave'
type='text'/>
<feature var='http://jabber.org/protocol/muc'/>
<feature var='muc_passwordprotected'/>
<feature var='muc_hidden'/>
<feature var='muc_temporary'/>
<feature var='muc_open'/>
<feature var='muc_unmoderated'/>
<feature var='muc_nonanonymous'/>
</query>
</iq>
But I am getting this result :
<iq xmlns="jabber:client" type="result" id="some ID" from="Group-ID" to="My Full JabberID">
<query xmlns="http://jabber.org/protocol/disco#info">
<feature var="http://jabber.org/protocol/disco#info">
</feature>
</query>
</iq>
Can any one help me what I am doing wrong.
THanks in advance.
If you want to get the room info , you can call the mothod on XMPPRoom
- (void)fetchConfigurationForm;
Then , get the room info in the room's Delegate method
- (void)xmppRoom:(XMPPRoom *)sender didFetchConfigurationForm:(NSXMLElement *)configForm;