SendBird - iOS: 无法接收相机照片,但可以接收存储的图像
SendBird - iOS: Cannot receive camera photo, but can receive stored image
我正在使用 SendBird 向我的应用程序添加发送图片功能。
在 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
我执行这段代码
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) {}];
当 imagePicker 的源类型为:UIImagePickerControllerSourceTypePhotoLibrary
.
时,此代码运行良好
如果我使用 imagePicker 发送图像,其来源类型是:UIImagePickerControllerSourceTypeCamera
那么
- (void)channel:(SBDBaseChannel *)sender didReceiveMessage:(SBDBaseMessage *)message
从未触发。
据我所知,来自 UIImagePickerControllerSourceTypeCamera
的 info
字典没有 UIImagePickerControllerReferenceURL
的对象。所以,imagePath
和 imageName
必须是 nil
。
sendFileMessageWithBinaryData:filename:type:size:data:completionHandler:
需要 filename
而不是 nil
。因为您生成 jpeg 数据,所以只需使用 @"image.jpg"
作为 filename
,如下所示:
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) {
}];
我正在使用 SendBird 向我的应用程序添加发送图片功能。
在 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
我执行这段代码
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) {}];
当 imagePicker 的源类型为:UIImagePickerControllerSourceTypePhotoLibrary
.
如果我使用 imagePicker 发送图像,其来源类型是:UIImagePickerControllerSourceTypeCamera
那么
- (void)channel:(SBDBaseChannel *)sender didReceiveMessage:(SBDBaseMessage *)message
从未触发。
据我所知,来自 UIImagePickerControllerSourceTypeCamera
的 info
字典没有 UIImagePickerControllerReferenceURL
的对象。所以,imagePath
和 imageName
必须是 nil
。
sendFileMessageWithBinaryData:filename:type:size:data:completionHandler:
需要 filename
而不是 nil
。因为您生成 jpeg 数据,所以只需使用 @"image.jpg"
作为 filename
,如下所示:
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) {
}];