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
iOS Check If Application Has Access to Microphone
Setting Up Uiscrollview to Swipe Between 3 View Controllers
How to Filter Firebase Data in Swift
Uisearchdisplaycontroller Without Dimming
Objective-C Wrapper for Cfunctionpointer to a Swift Closure
How to Access an Xcassets Directory on the Filesystem
How to Send Data from iPhone to Apple Watch in Os2 in Objective-C
Alamofire Fire Variable Type Has No Subscript Members
Swift UI Remove Extra List Empty Cells Without Navigation Controller
Xcode Error While Validation - "Your Binary Is Not Optimized for iPhone 5"
Pass Multiple Parameters to Addtarget
Ios: One Ibaction for Multiple Buttons
Ckquery from Private Zone Returns Only First 100 Ckrecords from in Cloudkit
How to Convert from Uiimage to Heif/Heic Data in Swift
How to Detect iOS 6 and All Minor Versions by User Agent
Uiscrollview Pauses Nstimer While Scrolling
Not Getting Email and Public Profile Using Facebook 4.4.0 Sdk