XMPPFramework - How can I update my own avatar image? - ios

I am developing an application in that I want to update my avatar image. I am following XEP-0153 guidelines to update my avatar image and I constructed an NSXMLElement correspond to the following code in XEP-0153 and sent that element through XMPPStream.
<iq from='juliet#capulet.com'
type='set'
id='vc1'>
<vCard xmlns='vcard-temp'>
<PHOTO>
<TYPE>image/jpeg</TYPE>
<BINVAL>
Base64-encoded-avatar-file-here!
</BINVAL>
</PHOTO>
</vCard>
</iq>
The server responses the following error:
<iq xmlns="jabber:client" type="error" id="vc1" to="vvreddy50#gmail.com/83557F96">
<vCard xmlns="vcard-temp">
<photo>
<type>image/jpeg</type>
<binval>Base64-encoded-avatar-file-here</binval>
</photo>
</vCard>
<error code="500" type="wait">
<internal-server-error xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">
</internal-server-error>
</error>
</iq>
Instead of <iq to='juliet#capulet.com' type='result' id='vc1'/>
Please can anyone post the code or the link related to update avatar image? Thanks in advance.

- (void)updateAvatar:(UIImage *)avatar
{
NSData *imageData = UIImagePNGRepresentation(avatar);
dispatch_queue_t queue = dispatch_queue_create("queue", DISPATCH_QUEUE_PRIORITY_DEFAULT);
dispatch_async(queue, ^{
XMPPvCardTempModule *vCardTempModule = [[XMPPHandler sharedInstance] xmppvCardTempModule];
XMPPvCardTemp *myVcardTemp = [vCardTempModule myvCardTemp];
[myVcardTemp setName:[NSString stringWithFormat:#"%#",name.text]];
[myVcardTemp setPhoto:imageData];
[vCardTempModule updateMyvCardTemp:myVcardTemp];
});
}

#import "XMPPvCardTemp.h"
- (void)updateAvatar:(UIImage *)avatar{
NSData *imageData1 = UIImageJPEGRepresentation(avatar,0.5);
NSXMLElement *vCardXML = [NSXMLElement elementWithName:#"vCard" xmlns:#"vcard-temp"];
NSXMLElement *photoXML = [NSXMLElement elementWithName:#"PHOTO"];
NSXMLElement *typeXML = [NSXMLElement elementWithName:#"TYPE"stringValue:#"image/jpeg"];
NSXMLElement *binvalXML = [NSXMLElement elementWithName:#"BINVAL" stringValue:[imageData1 base64Encoding]];
[photoXML addChild:typeXML];
[photoXML addChild:binvalXML];
[vCardXML addChild:photoXML];
XMPPvCardTemp *myvCardTemp = [[[self appDelegate] xmppvCardTempModule]myvCardTemp];
if (myvCardTemp) {
[myvCardTemp setPhoto:imageData1];
[[[self appDelegate] xmppvCardTempModule] updateMyvCardTemp
:myvCardTemp];
}
else{
XMPPvCardTemp *newvCardTemp = [XMPPvCardTemp vCardTempFromElement:vCardXML];
[[[self appDelegate] xmppvCardTempModule] updateMyvCardTemp:newvCardTemp];
}
}

From the XMPP Core RFC, <error type='wait'> means:
retry after waiting (the error is temporary)
so your code should wait a while and re-send the request.
(This is assuming that you are actually sending a base64-encoded JPEG image as the BINVAL of your vCard. The reply from the server doesn't correspond to the request you say you sent, so I'm assuming you've edited both. It would be better to include the exact request and reply in your question, but truncate the base64-encoded image to a few characters for concision.)

Related

Get list of Chat group using XMPPFramework

I am trying to fetch the list of available chat groups in my Ejabbered server with the help of XMPPFramework. Following is my code to fetch the list of Chat Group.
- (void) getChatGroupList{
XMPPJID *servrJID = [XMPPJID jidWithString:#"conference.Server"];
XMPPIQ *iq = [XMPPIQ iqWithType:#"get" to:servrJID];
[iq addAttributeWithName:#"from" stringValue:[[self xmppStream] myJID].full];
NSXMLElement *query = [NSXMLElement elementWithName:#"query"];
[query addAttributeWithName:#"xmlns" stringValue:#"http://jabber.org/protocol/disco#items"];
[iq addChild:query];
[[self xmppStream] sendElement:iq];
}
In response I am getting following XML inside didReceiveIQ
<presence xmlns="jabber:client" from="username#Server/38489493512952747921478847202003609" to="username# Server/38489493512952747921478847202003609"><priority>24</priority><x xmlns="vcard-temp:x:update"><photo/></x><c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="https://github.com/robbiehanson/XMPPFramework" ver="VyOFcFX6+YNmKssVXSBKGFP0BS4="/></presence>
Exact name of the group I can't see in the response. Can anyone help what is missing here or How can I get list of Group name and list of users inside each group?
Have you figure what happened?
From what I see, your request looks OK, but the response should be for other request.
And not sure what version XMPPFramework you are using, in the latest, there is a XMPPMUC class in XEP-0045. You can call discoverRoomsForServiceNamed to do the same stuff. Just make sure to implement XMPPMUCDelegate when you use it.

XMPP+iOS Delivered,SENT known SEEN Receipt not known

I have gone through the XEP 0184 and have done following implementation.
If XMPP is connected and packet then is send then i set the status for each message as SENT (✔︎) if I don't get following callback.
-(void)xmppStream:(XMPPStream *)sender didReceiveError:(id)error
If i get the received status from XEP 0184 implemented in Objective C, I set the status as Delivered (✔︎✔︎)
RECV: < message xmlns="jabber:client" from="+122232322#wer.com/2323"
to="+3343232322#wer.com/2223" lang="" >< received
xmlns="urn:xmpp:receipts" id="avv-33343"/ >< /message >
But my question is how to show the SEEN status for each message as readh XMPP 0079 that is Advanced Messaging protocol is doing this. But I could not find in Objective C.
Can anyone please help? If my direction is correct and I am missing something could you let me know?
A code snippet guidance would be much appreciated.
Here is my implementation.
Using the stack documentation help I have added the following lines to get the delivery receipts.
XMPPMessageDeliveryReceipts* xmppMessageDeliveryReceipts = [[XMPPMessageDeliveryReceipts alloc] initWithDispatchQueue:dispatch_get_main_queue()];
xmppMessageDeliveryReceipts.autoSendMessageDeliveryReceipts = YES;
xmppMessageDeliveryReceipts.autoSendMessageDeliveryRequests = YES;
[xmppMessageDeliveryReceipts activate:self.xmppStream];
Now due to this I get the following response for the send and RECV xml.
SEND: 111111111 for avv-33343 Id message.
RECV: < message xmlns="jabber:client" from="+122232322#wer.com/2323"
to="+3343232322#wer.com/2223" lang="" >< received
xmlns="urn:xmpp:receipts" id="avv-33343"/ >< /message >
But this is just giving me info that the message is delivered but how to send the SEEN receipts like above to intimate the sender that the other end user have acknowledged + SEEN the message.
Something like this ... RECV: < seen xmlns="urn:xmpp:receipts" id="222-4444"/ >
For seen status use same functionality as send a normal message with same id which message received and you want to mark seen on Sender device,
When on sender device receive a static message #"to#fromSeen" with same message id for sent/delivered message, When receiver get exist msg id already in db then your purpose resolve .
Code for send seen status
NSString *bodymessageString = [NSString stringWithFormat:#"to#fromSeen"];
NSString *str_loginUser = [NSString stringWithFormat:#"%##%#", [[NSUserDefaults standardUserDefaults]valueForKey:#"mobile"],kXMPPServer ];
NSString *str_OtherUser = [NSString stringWithFormat:#"%##%#",str_OtherUserRegName,kXMPPServer];
NSXMLElement *body = [NSXMLElement elementWithName:#"body"];
[body setStringValue:bodymessageString];
NSXMLElement *message = [NSXMLElement elementWithName:#"message"];
[message addAttributeWithName:#"type" stringValue:#"chat"];
[message addAttributeWithName:#"from" stringValue:str_loginUser];
// [[[delegate xmppStream] myJID] bare]
[message addAttributeWithName:#"to" stringValue:str_OtherUser];
// NSString *messageID= [XMPPStream generateUUID];
[message addAttributeWithName:#"id" stringValue:str_msgID];
// NSXMLElement *request = [NSXMLElement elementWithName:#"request" xmlns:#"urn:xmpp:receipts"];
// [message addChild:request];
[message addChild:body];
[[delegate xmppStream] sendElement:message];
[ChatData GetUpdateToDatabase:str_msgID :#"Seen"];
Code for check message status in appdelegate file
if ([message isChatMessageWithBody])
{
if ([msg isEqualToString:#"to#fromSeen"])
{
BOOL is_Exist;
is_Exist = [ChatData GetAllReadyAvailable :message.elementID];
if (is_Exist == YES)
{
NSString *str_status = [ChatData getstatusChatBy:message.elementID];
if (![str_status isEqualToString:#"Seen"])
{
[ChatData GetUpdateToDatabase:message.elementID :#"Seen"];
}
}
}
else
{
BOOL is_Exist;
is_Exist = [ChatData GetAllReadyAvailable :message.elementID];
if (is_Exist == NO)
{
// Store message in DB
}
}
}
else if ([message hasReceiptResponse])
{
}
else if([message isErrorMessage])
{}

XMPPFramework - How to transfer image from one device to another?

I have made one-to-one chat using XMPP protocol. Now, I would like to send image and video in my application. I researched about the file transfer but I didn't find a solution. I have also used the code below for Socket connection.
Please advice me on how I can go about doing this.
[TURNSocket setProxyCandidates:#[#"MyserverHost-desktop"]];
XMPPJID *jid = [XMPPJID jidWithString:#"1254225445#MyserverHost-desktop"];
TURNSocket *turnSocket = [[TURNSocket alloc] initWithStream:[[self appDelegate]xmppStream] toJID:jid];
[app.turnSocketArray addObject:turnSocket];
[turnSocket startWithDelegate:self delegateQueue:dispatch_get_main_queue()];
[turnSocket release];
- (void)turnSocket:(TURNSocket *)sender didSucceed:(GCDAsyncSocket *)socket
{
}
- (void)turnSocketDidFail:(TURNSocket *)sender
{
}
Every time connection fail method call..
Thanks.
you need push the image to server and you will reveice a url from server .then you can send the url to another device by xmpp protocol. in the end. download the image from server by the received url.
xmpp also can send image . But that's a big xml message for xmpp server .that's not a great solution.
Try this...
NSData *dataF = UIImagePNGRepresentation(SendImage);
NSString *imgStr=[dataF base64Encoding];
NSXMLElement *body = [NSXMLElement elementWithName:#"body"];
[body setStringValue:messageStr];
NSXMLElement *imgAttachement = [NSXMLElement elementWithName:#"attachment"];
[imgAttachement setStringValue:imgStr];
NSXMLElement *message = [NSXMLElement elementWithName:#"message"];
[message addAttributeWithName:#"type" stringValue:#"chat"];
[message addAttributeWithName:#"to" stringValue:chatWithUser];
[message addChild:body];
[message addChild:imgAttachement];
[self.xmppStream sendElement:message];
I hope this will help you...

XMPPFramework: Trying to update nickname on VCard

This question is as simple as its title says: I'm trying to update a user nickname on his VCard but I cannot. I'm using this code:
dispatch_queue_t queue = dispatch_queue_create("queue", DISPATCH_QUEUE_PRIORITY_DEFAULT);
dispatch_async(queue, ^{
XMPPvCardTemp *myVcardTemp = [[[self appDelegate] xmppvCardTempModule] myvCardTemp];
[myVcardTemp setNickname:#"a_nickname"];
[[[self appDelegate] xmppvCardTempModule] updateMyvCardTemp:myVcardTemp];
});
I cannot imagine why this piece of code don't want to work while the same piece, but updating photo, is working like a charm:
NSData *imageData = UIImagePNGRepresentation(anImage);
dispatch_queue_t queue = dispatch_queue_create("queue", DISPATCH_QUEUE_PRIORITY_DEFAULT);
dispatch_async(queue, ^{
XMPPvCardTemp *myVcardTemp = [[[self appDelegate] xmppvCardTempModule] myvCardTemp];
[myVcardTemp setPhoto:imageData];
[[[self appDelegate] xmppvCardTempModule] updateMyvCardTemp:myVcardTemp];
});
Any help would be appreciated... this is driving me crazy
NOTES: I'm using OpenFire as XMPP server
And this is the stanza the server returns me when I'm trying to update the nickname
RECV: <iq xmlns="jabber:client" type="result" from="7db55e68-cb18-4826-befd-0eb9269637aa#000.000.000.000" to="7db55e68-cb18-4826-befd-0eb9269637aa#000.000.000.000/2cfc4f88"><chat_jorges xmlns="vcard-temp"><NICKNAME>chat_jorges</NICKNAME></chat_jorges></iq>
(I changed my server's ip for 000.000.000.000)
EDIT : I WAS TOTALLY WRONG DON'T READ THIS
Actually when I read the source code of XMPP, I wonder how it could set a value.
In XMPPvCardTempBase.h :
#define XMPP_VCARD_SET_STRING_CHILD(Value, Name) NSXMLElement *elem = [self elementForName:(Name)];
//it looks like a get and not a set??
And in XMPPvCardTemp.m :
- (void)setNickname:(NSString *)nick {
XMPP_VCARD_SET_STRING_CHILD(nick, #"NICKNAME");
}
Maybe there is something as KVC somewhere...
Can you try this in the source code:
- (void)setNickname:(NSString *)nick {
XMPP_VCARD_SET_STRING_CHILD(nick, #"NICKNAME") = nick ;
}

MUC How-to with XMPPFramework

I am developing an iOS XMPP chat app that utilizes Robbie Hanson's XMPPFramework.
The most important functionalities have been implemented - sending and receiving messages. Basically, I've built a basic functional chat app already, with a little eye candy of course.
Now, the problem I have is regarding MUC. The codes I saw from other websites show that there is a method initWithRoomName in XMPPRoom. However, this method is absent in the git repo I cloned. So, what is the alternative to this? Or, if there is none, how do I go about creating rooms using XMPPFramework?
Thanks.
Below is how I got my own problem solved. Note that this solution does not involve XMPPRoom at all. First, I created a method that, depending on the situation, either creates or enters a room. (Per XMPP documentation, the XML request for creating is the same is the same as the one you would send to enter a room; that is, if the room has does not exist yet when you enter it, the service will create it for you.)
Here we go. This is the method that creates/enters a room. What this method does is send a presence to the room which you intend to create/enter. If you are the first to enter a room and the room has not been created yet, you automatically become its owner and moderator.
- (void)createOrEnterRoom:(NSString *)roomName
{
//here we enter a room, or if the room does not yet exist, this method creates it
//per XMPP documentation: "If the room does not yet exist, the service SHOULD create the room"
//this method accepts an argument which is what you would baptize the room you wish created
NSXMLElement *presence = [NSXMLElement elementWithName:#"presence"];
NSString *room = [roomName stringByAppendingString:#"#conference.jabber.com/iMac"];
[presence addAttributeWithName:#"to" stringValue:room];
NSXMLElement *x = [NSXMLElement elementWithName:#"x" xmlns:#"http://jabber.org/protocol/muc"];
NSXMLElement *history = [NSXMLElement elementWithName:#"history"];
[history addAttributeWithName:#"maxstanzas" stringValue:#"50"];
[x addChild:history];
[presence addChild:x];
[[self xmppStream] sendElement:presence];
}
Next, in the AppDelegate where XMPPStream methods are declared we filter the XML response we receive in the didReceivePresence method by checking the status code sent by the server. If the status code is 201, bingo! The room creation went just fine. Status codes other than 201 mean different things, but let's focus on 201 for our purpose.
- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence
{
NSXMLElement *x = [presence elementForName:#"x" xmlns:#"http://jabber.org/protocol/muc#user"];
for (NSXMLElement *status in [x elementsForName:#"status"])
{
switch ([status attributeIntValueForName:#"code"])
{
case 201: [self notifyRoomCreationOk:room];
}
}
}
Then, we tell the server that what we are creating a room of the type "instant," which means that we will send an IQ element telling it room defaults. notifyRoomCreationOk is a delegate method called in a different view when the room creation succeeds, after all I have to record the room in a text file to make it persistent so that the next time I open the app the room I created before will be visible. In my notifyRoomCreationOk method, I have sendDefaultRoomConfig which, basically, describes what is stated in the first sentence of this paragraph.
-(void)sendDefaultRoomConfig:(NSString *)room
{
NSXMLElement *x = [NSXMLElement elementWithName:#"x" xmlns:#"jabber:x:data"];
[x addAttributeWithName:#"type" stringValue:#"submit"];
NSXMLElement *query = [NSXMLElement elementWithName:#"query" xmlns:#"http://jabber.org/protocol/muc#owner"];
[query addChild:x];
XMPPIQ *iq = [XMPPIQ iq];
[iq addAttributeWithName:#"id" stringValue:[NSString stringWithFormat:#"inroom-cr%#", room]];
[iq addAttributeWithName:#"to" stringValue:room];
[iq addAttributeWithName:#"type" stringValue:#"set"];
[iq addChild:query];
[[self xmppStream ] sendElement:iq];
}
Make sure that you have XMPPStream enabled on the views that call the above methods, otherwise, these won't work. That's all there is to it. Have fun XMPP-ing!
XMPPRoom *room = [[XMPPRoom alloc] initWithRoomName:#"user101#conference.jabber.org/room" nickName:#"room"];
[room createOrJoinRoom];
[room sendInstantRoomConfig];
[room setInvitedUser:#"ABC#jabber.org"];
[room activate:[self xmppStream]];
[room inviteUser:jid1 withMessage:#"hello please join."];
[room sendMessage:#"HELLO"];
the user ABC#jabber.org should receive the invite message
Your post is old, however now I would do it like this:
- (void)createRoomWithJid:(XMPPJID*)roomJID
{
XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:self.xmppRoomHybridStorage
jid:roomJID
dispatchQueue:dispatch_get_main_queue()];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom activate:self.xmppStream];
[xmppRoom joinRoomUsingNickname:self.xmppStream.myJID.user
history:nil
password:nil];
}
Create chat room by given below code using XMPPFRAMWORK.
let roomStorage: XMPPRoomMemoryStorage = XMPPRoomMemoryStorage()
/**
* Remember to add 'conference' in your JID like this:
* e.g. uniqueRoomJID#conference.yourserverdomain
*/
let roomJID: XMPPJID = XMPPJID.jidWithString("chatRoom_name#conference.myhostname")
let xmppRoom: XMPPRoom = XMPPRoom(roomStorage: roomStorage,
jid: roomJID,
dispatchQueue: dispatch_get_main_queue())
xmppRoom.activate(SKxmpp.manager().xmppStream)
xmppRoom.addDelegate(self, delegateQueue: dispatch_get_main_queue())
xmppRoom.joinRoomUsingNickname(SKxmpp.manager().xmppStream.myJID.user, history: nil, password: nil)
xmppRoom.fetchConfigurationForm()

Resources