From b9705cfe06ec9894a50e5430df692ef7142fae32 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 16 Mar 2017 15:29:30 -0300 Subject: [PATCH] Fix sending attachments from the camera. // FREEBIE --- .../view controllers/MessagesViewController.m | 45 ++++++++++++------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/Signal/src/view controllers/MessagesViewController.m b/Signal/src/view controllers/MessagesViewController.m index 5689de664..12ffdcab2 100644 --- a/Signal/src/view controllers/MessagesViewController.m +++ b/Signal/src/view controllers/MessagesViewController.m @@ -1916,6 +1916,8 @@ typedef enum : NSUInteger { - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { + OWSAssert([NSThread isMainThread]); + [UIUtil modalCompletionBlock](); [self resetFrame]; @@ -1928,27 +1930,36 @@ typedef enum : NSUInteger { // Video picked from library or captured with camera NSURL *videoURL = info[UIImagePickerControllerMediaURL]; - [self sendQualityAdjustedAttachmentForVideo:videoURL]; + [self dismissViewControllerAnimated:YES + completion:^{ + [self sendQualityAdjustedAttachmentForVideo:videoURL]; + }]; } else if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) { // Static Image captured from camera UIImage *imageFromCamera = [info[UIImagePickerControllerOriginalImage] normalizedImage]; - if (imageFromCamera) { - SignalAttachment *attachment = [SignalAttachment imageAttachmentWithImage:imageFromCamera - dataUTI:(NSString *) kUTTypeJPEG]; - if (!attachment || - [attachment hasError]) { - DDLogWarn(@"%@ %s Invalid attachment: %@.", - self.tag, - __PRETTY_FUNCTION__, - attachment ? [attachment errorMessage] : @"Missing data"); - failedToPickAttachment(nil); - } else { - [self sendMessageAttachment:attachment]; - } - } else { - failedToPickAttachment(nil); - } + + [self dismissViewControllerAnimated:YES + completion:^{ + OWSAssert([NSThread isMainThread]); + + if (imageFromCamera) { + SignalAttachment *attachment = [SignalAttachment imageAttachmentWithImage:imageFromCamera + dataUTI:(NSString *) kUTTypeJPEG]; + if (!attachment || + [attachment hasError]) { + DDLogWarn(@"%@ %s Invalid attachment: %@.", + self.tag, + __PRETTY_FUNCTION__, + attachment ? [attachment errorMessage] : @"Missing data"); + failedToPickAttachment(nil); + } else { + [self sendMessageAttachment:attachment]; + } + } else { + failedToPickAttachment(nil); + } + }]; } else { // Non-Video image picked from library