Kiran K
Kiran K

Reputation: 949

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.

Upvotes: 0

Views: 3412

Answers (2)

Bhrigesh
Bhrigesh

Reputation: 871

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...

Upvotes: 4

user1122949
user1122949

Reputation: 165

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.

Upvotes: 5

Related Questions