From 8d80c0d6a7e2a8fa6f2b4e2483bd8faae8b68048 Mon Sep 17 00:00:00 2001 From: manuroe Date: Mon, 5 Feb 2018 15:36:56 +0100 Subject: [PATCH 1/2] Share: The extension crashes if you try to share a GIF image (#1759) --- .../Model/ShareExtensionManager.m | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/RiotShareExtension/Model/ShareExtensionManager.m b/RiotShareExtension/Model/ShareExtensionManager.m index 7068c97560..e98dcb90db 100644 --- a/RiotShareExtension/Model/ShareExtensionManager.m +++ b/RiotShareExtension/Model/ShareExtensionManager.m @@ -228,8 +228,11 @@ - (void)sendContentToRoom:(MXRoom *)room failureBlock:(void(^)(NSError *error))f UIAlertController *compressionPrompt = [self compressionPromptForImage:self.pendingImages.firstObject shareBlock:^{ [self sendImages:self.pendingImages withProviders:item.attachments toRoom:room extensionItem:item failureBlock:failureBlock]; }]; - - [self.delegate shareExtensionManager:self showImageCompressionPrompt:compressionPrompt]; + + if (compressionPrompt) + { + [self.delegate shareExtensionManager:self showImageCompressionPrompt:compressionPrompt]; + } } } }]; @@ -630,13 +633,29 @@ - (void)sendImages:(NSMutableArray *)imageDatas withProviders:(NSArray*)itemProv } else if ([itemProvider hasItemConformingToTypeIdentifier:(__bridge NSString *)kUTTypeJPEG]) { - // Use jpeg format by default. mimeType = @"image/jpeg"; if (convertedImage != image) { imageData = UIImageJPEGRepresentation(convertedImage, 0.9); } } + else + { + // Other image types like GIF + NSString *imageFileName = itemProvider.registeredTypeIdentifiers[0]; + mimeType = (__bridge_transfer NSString *) UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)imageFileName, kUTTagClassMIMEType); + } + + // Sanity check + if (!mimeType) + { + NSLog(@"[ShareExtensionManager] sendImage failed. Cannot determine MIME type of %@", itemProvider); + if (failureBlock) + { + failureBlock(nil); + } + return; + } UIImage *thumbnail = nil; // Thumbnail is useful only in case of encrypted room From ba34f3814b7fe494500cf0a6a369212bc17ded27 Mon Sep 17 00:00:00 2001 From: manuroe Date: Mon, 5 Feb 2018 15:44:56 +0100 Subject: [PATCH 2/2] Share: Make sure the progress bar is always displayed The switch to the main thread should be done earlier but I do not want to break things --- .../ViewController/RoomsListViewController.m | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/RiotShareExtension/ViewController/RoomsListViewController.m b/RiotShareExtension/ViewController/RoomsListViewController.m index c3acf02ceb..54cf6d0bb7 100644 --- a/RiotShareExtension/ViewController/RoomsListViewController.m +++ b/RiotShareExtension/ViewController/RoomsListViewController.m @@ -305,24 +305,30 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView - (void)shareExtensionManager:(ShareExtensionManager *)extensionManager showImageCompressionPrompt:(UIAlertController *)compressionPrompt { - [compressionPrompt popoverPresentationController].sourceView = self.view; - [compressionPrompt popoverPresentationController].sourceRect = self.view.frame; - [self presentViewController:compressionPrompt animated:YES completion:nil]; + dispatch_async(dispatch_get_main_queue(), ^{ + [compressionPrompt popoverPresentationController].sourceView = self.view; + [compressionPrompt popoverPresentationController].sourceRect = self.view.frame; + [self presentViewController:compressionPrompt animated:YES completion:nil]; + }); } - (void)shareExtensionManager:(ShareExtensionManager *)extensionManager didStartSendingContentToRoom:(MXRoom *)room { - if (!self.hudView) - { - self.parentViewController.view.userInteractionEnabled = NO; - self.hudView = [MXKPieChartHUD showLoadingHudOnView:self.view WithMessage:NSLocalizedStringFromTable(@"sending", @"Vector", nil)]; - [self.hudView setProgress:0.0]; - } + dispatch_async(dispatch_get_main_queue(), ^{ + if (!self.hudView) + { + self.parentViewController.view.userInteractionEnabled = NO; + self.hudView = [MXKPieChartHUD showLoadingHudOnView:self.view WithMessage:NSLocalizedStringFromTable(@"sending", @"Vector", nil)]; + [self.hudView setProgress:0.0]; + } + }); } - (void)shareExtensionManager:(ShareExtensionManager *)extensionManager mediaUploadProgress:(CGFloat)progress { - [self.hudView setProgress:progress]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self.hudView setProgress:progress]; + }); } @end