Filetransfer Using Xmppframework in iOS

How to transfer image One device to another device using xmpp framework on iphone?

Even I am not sending the image directly to xmpp because it takes a lot time.

In my project I message can be string and it can be image and I found there is only one method to send message i.e..

[xmppRoom sendMessageWithBody:@"Your msg"];

So for sending the image First I am converting it to base64 then uploading it to my server and getting the URL for that image from server. Once we get the URL just pass that URL in Above method.

Problem here I was facing was how to segregate normal messages and URL (Images)

So for sending normal text I am directly sending it above function but for sending URL I am sending the nsdictionary i.e. I am converting nsdictionary to string and sending it in above function

NSDictionary *dict = @{@"type":@"image",
@"url":@"Url of your image"};

NSString *newMessage = [NSString stringWithFormat:@"%@",dict];

[appDelegate.xmppRoom sendMessageWithBody:newMessage];

For segregating normal message and Image in -

- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
{

messages *msg = [messages new];

NSDictionary *dictOfMedia = [NSPropertyListSerialization
propertyListWithData:[[[message elementForName:@"body"] stringValue] dataUsingEncoding:NSUTF8StringEncoding]
options:kNilOptions
format:NULL
error:NULL];

if ([dictOfMedia objectForKey:@"type"])
{
msg.mediaType = [dictOfMedia objectForKey:@"type"];
msg.url = [dictOfMedia objectForKey:@"url"];
}
else
{
msg.msg = [[message elementForName:@"body"] stringValue];
}

}

messages is my model class you can use simply use nsstring for testing purpose.

After this just use any open source project for downloading the image or perform lazy loading on your own.

Hope this will help you :)

XMPPFramework- Error 405 not-allowed in File Transfer

Correct following line

[x addAttributeWithName:@"type" stringValue:@"from"];

With

[x addAttributeWithName:@"type" stringValue:@"form"];

Here you have written "from" instead of "form". For more details you can visit following link: http://xmpp.org/extensions/xep-0096.html



Related Topics



Leave a reply



Submit