我正在尝试使用xmpp框架为ios开发聊天应用程序。我收到了以下错误。实际上,我可以发送图像的详细信息。当我从iPhone发送图像到火花时,它会显示图像的名称和大小。但是,当我接受该图像时,数据没有被传输。
2014-05-12 11:08:15:310 iPhoneXMPP[407:5d2f] RECV: <iq xmlns="jabber:client" id="4F89EF6C-4A7B-469C-AF0A-B3AD751C1C5E" to="rumit@imt-110/5d4aec79" from="paresh@imt-110/Spark 2.6.3" type="error"><query xmlns="http://jabber.org/protocol/bytestreams" sid="" mode="tcp"><streamhost jid="proxy.imt-110" host="192.168.0.145" port="7777"/></query><error code="406" type="MODIFY"><not-acceptable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>
2014-05-12 11:08:15:310 iPhoneXMPP[407:60b] iPhoneXMPPAppDelegate: xmppStream:didReceiveIQ:
2014-05-12 11:08:15.311 iPhoneXMPP[407:60b] Couldn't set up bytestream for file transfer! --- <TURNSocket: 0xb077140>
请参阅下面的我的代码以发送图像。
- (void)sendToOtherDevice:(NSData *)fileData2 receiverJid:(NSString *)receiverJid
{
XMPPJID *jid = [XMPPJID jidWithString:receiverJid];
if ([jid.domain isEqualToString:@"Rumit@imt-110"]) {
[TURNSocket setProxyCandidates:[NSArray arrayWithObjects:jid.domain, nil]];
} else {
[TURNSocket setProxyCandidates:[NSArray arrayWithObjects:jid.domain, @"Rumit@imt-110", nil]];
}
TURNSocket *socket = [[TURNSocket alloc] initWithStream:[[self appDelegate] xmppStream] toJID:jid sid:[[self appDelegate] sidVal]];
socket.fileName = @"defaultPerson.png";
socket.fileData = fileData2;
[socket startWithDelegate:self delegateQueue:dispatch_get_main_queue()];
[[[self appDelegate] xmppStream] addDelegate:self delegateQueue:dispatch_get_main_queue()];
}
我是否必须在didreceiveIQ方法中写任何东西?当我按下“接受火花”时,它会被调用。
先谢谢。
答案 0 :(得分:0)
NSData *data = UIImageJPEGRepresentation(chosenImage, 1.0);
NSLog(@"Size of Image(bytes):%lu",(unsigned long)[data length]);
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:@"13iapp@jabbim.cz"];
[message addChild:message];
[message addChild:ImgAttachement];
[[[PDAppDelegate sharedDelegate] xmppStream]sendElement:message];//( [[PDAppDelegate sharedDelegate] xmppStream]) that is object of XMPPStream