0
我想傳輸圖像和視頻。我能夠傳輸文本,但無法傳輸文件。iOS和XMPP客戶端
這裏是傳輸文件的代碼 -
NSString *messageStr = self.textView.text;
UIImage *imagePic = [UIImage imageNamed:@"apple.png"];
if ([messageStr length] > 0 || [imagePic isKindOfClass:[UIImage class]]) {
NSXMLElement *body = [NSXMLElement elementWithName: @"body"];
[body setStringValue:messageStr];
NSMutableDictionary *m = [[NSMutableDictionary alloc]init];
NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
[message addAttributeWithName:@"type" stringValue:@"chat"];
[message addAttributeWithName:@"to" stringValue:self.rosterJid];
[message addChild:body];
if ([imagePic isKindOfClass:[UIImage class]]) {
[m setObject:imagePic forKey:@"image"];
NSData *dataPic = UIImagePNGRepresentation(imagePic);
NSXMLElement *photo = [NSXMLElement elementWithName:@"PHOTO"];
NSXMLElement *binval = [NSXMLElement elementWithName:@"BINVAL"];
[photo addChild:binval];
NSString *base64String = [dataPic base64EncodedStringWithOptions:0];
[binval setStringValue:base64String];
[message addChild:photo];
}
[[[self appDelegate] xmppStream] sendElement: message];
self.textView.text = @"";
}
如何接收文件? 在此先感謝
您是否在'didRecieveMessage'中收到了消息? –
是的。我正進入(狀態。 – user1589516