简体   繁体   中英

SendBird - iOS: Cannot receive camera photo, but can receive stored image

I'm adding a send picture feature to my app using SendBird.

On - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info I execute this code

NSData *imageFileData = UIImageJPEGRepresentation(info[UIImagePickerControllerOriginalImage], 0.5);
NSURL* imagePath = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
NSString* imageName = [imagePath lastPathComponent];

[self.currentChannel sendFileMessageWithBinaryData:imageFileData filename:imageName type:@"image/jpg" size:[imageFileData length] data:nil completionHandler:^(SBDFileMessage * _Nullable fileMessage, SBDError * _Nullable error) {}];

This code works well when the imagePicker's sourcetype is: UIImagePickerControllerSourceTypePhotoLibrary .

If I send an image with imagePicker which's sourcetype is: UIImagePickerControllerSourceTypeCamera then

- (void)channel:(SBDBaseChannel *)sender didReceiveMessage:(SBDBaseMessage *)message is never triggered.

As I know, the info dictionary from UIImagePickerControllerSourceTypeCamera doesn't have an object for UIImagePickerControllerReferenceURL . So, the imagePath and the imageName must be nil .

The sendFileMessageWithBinaryData:filename:type:size:data:completionHandler: needs filename that is not nil . Because you generate jpeg data, just use @"image.jpg" as the filename like this:

NSData *imageFileData = UIImageJPEGRepresentation(info[UIImagePickerControllerOriginalImage], 0.5);

[self.currentChannel sendFileMessageWithBinaryData:imageFileData filename:@"image.jpg" type:@"image/jpg" size:[imageFileData length] data:nil completionHandler:^(SBDFileMessage * _Nullable fileMessage, SBDError * _Nullable error) {
}];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM