在iPhone上使用xmpp框架发送图像

发布于 2024-10-09 04:38:59 字数 93 浏览 0 评论 0原文

我在 iPhone 上使用 XMPP 框架作为我的聊天应用程序。我想使用 XMPP 框架从我的应用程序发送图像。谁能建议我,该怎么做?

任何帮助将不胜感激。

I am using XMPP framework on iPhone for my chatting application. I want to send image from my app using the XMPP framework. Can anyone suggest me, how to do this?

Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

七七 2024-10-16 04:38:59

添加额外的标签,例如

<attachment>base64 of your image </attachment>

“Thus send your image”,将其转换为 base64 字符串,然后在接收端将其转换回图像。

只需将 Uiimage 转换为 Base64 编码,然后通过 xmpp 将其作为带有任何额外标签(如附件)的消息发送。然后在接收方获取包含 Base64 内容的消息并将 Base64 编码的字符串转换回 UIImage
编码和解码的代码在此链接中:

http://iphonesdksnippets.com/post/2010/03/14/Convert-image-tofrom-text-%28Base64%29.aspx

...请参考它..如果您有任何疑问或者您想要一个简短的解释,只需在这里评论我会回复它..

Add an extra tag such as

<attachment>base64 of your image </attachment>

Thus sent your image in the sender side by converting it to base64 string and convert the base64 string back into image in the receiver side.

Just convert the Uiimage into a base64encoded coding and then sent it through xmpp as a message with any extra tag like attachement.. Then in the receiver side get the message with the base64 content and convert back the base64encoded string into UIImage
The code for encode and decode is in this link :

http://iphonesdksnippets.com/post/2010/03/14/Convert-image-tofrom-text-%28Base64%29.aspx

... Just refer it.. If you have any doubt or you want a brief explanation, just comment here i will respond to it..

泪意 2024-10-16 04:38:59
    NSData *data = UIImageJPEGRepresentation(chosenImage, 1.0);

    Base64Transcoder *base64 = [[Base64Transcoder alloc] init];
    NSString *imgStr = [base64 base64EncodedStringfromData:data];


    NSXMLElement *ImgAttachement = [NSXMLElement elementWithName:@"attachment"];
    [ImgAttachement setStringValue:imgStr];
     NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
   [body setStringValue:@"image test"];


    NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
    [message addAttributeWithName:@"type" stringValue:@"chat"];
    [message addAttributeWithName:@"to" stringValue:@"[email protected]"];// [NSString stringWithFormat:@"%@@192.168.1.193",self.jabber_id]];

    [message addChild:message];
    [message addChild:ImgAttachement];

     [[[PDAppDelegate sharedDelegate] xmppStream]sendElement:message];
    NSData *data = UIImageJPEGRepresentation(chosenImage, 1.0);

    Base64Transcoder *base64 = [[Base64Transcoder alloc] init];
    NSString *imgStr = [base64 base64EncodedStringfromData:data];


    NSXMLElement *ImgAttachement = [NSXMLElement elementWithName:@"attachment"];
    [ImgAttachement setStringValue:imgStr];
     NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
   [body setStringValue:@"image test"];


    NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
    [message addAttributeWithName:@"type" stringValue:@"chat"];
    [message addAttributeWithName:@"to" stringValue:@"[email protected]"];// [NSString stringWithFormat:@"%@@192.168.1.193",self.jabber_id]];

    [message addChild:message];
    [message addChild:ImgAttachement];

     [[[PDAppDelegate sharedDelegate] xmppStream]sendElement:message];
空袭的梦i 2024-10-16 04:38:59

将文件放入 WebDAV 服务器并通过 XMPP 发送 URL,使用 XEP-0065 ,或XEP-0047。许多提出这个问题的人都会选择 XEP-47,但这几乎总是错误的选择,除非文件非常小,因为许多服务器会因为发送大量数据而导致潜在的拒绝服务而对您的连接进行惩罚。

Either put the file to a WebDAV server and send the URL over XMPP, use XEP-0065, or XEP-0047. Many who ask this question choose XEP-47, but that is almost always the wrong choice unless the files are very small, since many servers will penalize your connection as a potential denial of service for sending large amounts of data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文