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

早过忘川 提交于 2019-12-08 10:38:24

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/18327203/xmppframework-how-to-transfer-image-from-one-device-to-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!