From a3a7bc02facc7558a1bf5c5d7f87a4dd8e279ff6 Mon Sep 17 00:00:00 2001 From: Benjamin Verdier Date: Wed, 20 Jun 2018 15:25:37 +0200 Subject: [PATCH 01/18] switch ALAssetLibrary to Photos in manager --- Classes/LinphoneManager.h | 2 +- Classes/LinphoneManager.m | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index c1eab0464..3b8650616 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -21,6 +21,7 @@ #import #import #import +#import #import #import @@ -225,7 +226,6 @@ typedef struct _LinphoneManagerSounds { @property (nonatomic, assign) BOOL speakerEnabled; @property (nonatomic, assign) BOOL bluetoothAvailable; @property (nonatomic, assign) BOOL bluetoothEnabled; -@property (readonly) ALAssetsLibrary *photoLibrary; @property (readonly) NSString* contactSipField; @property (readonly,copy) NSString* contactFilter; @property (copy) void (^silentPushCompletion)(UIBackgroundFetchResult); diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 33deccc6d..66af14910 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -263,7 +263,6 @@ struct codec_name_pref_table codec_pref_table[] = {{"speex", 8000, "speex_8k_pre _fileTransferDelegates = [[NSMutableArray alloc] init]; _linphoneManagerAddressBookMap = [[OrderedDictionary alloc] init]; pushCallIDs = [[NSMutableArray alloc] init]; - _photoLibrary = [[ALAssetsLibrary alloc] init]; _isTesting = [LinphoneManager isRunningTests]; [self renameDefaultSettings]; [self copyDefaultSettings]; From f25f0c74be96ce7b0494152392a3a624f79d7936 Mon Sep 17 00:00:00 2001 From: Benjamin Verdier Date: Wed, 20 Jun 2018 15:26:58 +0200 Subject: [PATCH 02/18] Change image saving method to be Photos framework compliant --- Classes/ChatConversationView.m | 48 ++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index 7368d9e07..614db53be 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -17,6 +17,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#import + #import "ChatConversationView.h" #import "PhoneMainView.h" #import "Utils.h" @@ -309,29 +311,29 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)saveAndSend:(UIImage *)image url:(NSURL *)url withQuality:(float)quality{ // photo from Camera, must be saved first if (url == nil) { - [LinphoneManager.instance.photoLibrary - writeImageToSavedPhotosAlbum:image.CGImage - orientation:(ALAssetOrientation)[image imageOrientation] - completionBlock:^(NSURL *assetURL, NSError *error) { - if (error) { - LOGE(@"Cannot save image data downloaded [%@]", [error localizedDescription]); - - UIAlertController *errView = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Transfer error", nil) - message:NSLocalizedString(@"Cannot write image to photo library", - nil) - preferredStyle:UIAlertControllerStyleAlert]; - - UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) {}]; - - [errView addAction:defaultAction]; - [self presentViewController:errView animated:YES completion:nil]; - } else { - LOGI(@"Image saved to [%@]", [assetURL absoluteString]); - [self startImageUpload:image url:assetURL withQuality:quality]; - } - }]; + __block NSURL *assetURL = nil; + [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ + [PHAssetChangeRequest creationRequestForAssetFromImage:image]; + } completionHandler:^(BOOL success, NSError *error) { + if (success) { + LOGI(@"Image saved to [%@]", [assetURL absoluteString]); + [self startImageUpload:image url:assetURL withQuality:quality]; + } else { + LOGE(@"Cannot save image data downloaded [%@]", [error localizedDescription]); + + UIAlertController *errView = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Transfer error", nil) + message:NSLocalizedString(@"Cannot write image to photo library", + nil) + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) {}]; + + [errView addAction:defaultAction]; + [self presentViewController:errView animated:YES completion:nil]; + } + }]; } else { [self startImageUpload:image url:url withQuality:quality]; } From 385c82838960ab38fd9b234bd98bf4d9a6698140 Mon Sep 17 00:00:00 2001 From: Benjamin Verdier Date: Wed, 20 Jun 2018 15:27:19 +0200 Subject: [PATCH 03/18] indentation fix --- Classes/LinphoneUI/UIChatBubblePhotoCell.m | 46 +++++++++++----------- Classes/LinphoneUI/UIChatBubbleTextCell.m | 10 ++--- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Classes/LinphoneUI/UIChatBubblePhotoCell.m b/Classes/LinphoneUI/UIChatBubblePhotoCell.m index d5217c68e..65e0d4b9a 100644 --- a/Classes/LinphoneUI/UIChatBubblePhotoCell.m +++ b/Classes/LinphoneUI/UIChatBubblePhotoCell.m @@ -191,29 +191,29 @@ [_messageImageView startLoading]; __block LinphoneChatMessage *achat = self.message; [LinphoneManager.instance.photoLibrary assetForURL:imageUrl resultBlock:^(ALAsset *asset) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) { - if (achat != self.message) // Avoid glitch and scrolling - return; - - if (asset) { - [self loadAsset:asset]; - } - else { - [LinphoneManager.instance.photoLibrary - enumerateGroupsWithTypes:ALAssetsGroupAll - usingBlock:^(ALAssetsGroup *group, BOOL *stop) { - [group enumerateAssetsWithOptions:NSEnumerationReverse - usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { - if([result.defaultRepresentation.url isEqual:imageUrl]) { - [self loadAsset:result]; - *stop = YES; - } - }]; - } - failureBlock:^(NSError *error) { - LOGE(@"Error: Cannot load asset from photo stream - %@", [error localizedDescription]); - }]; - } - }); + if (achat != self.message) // Avoid glitch and scrolling + return; + + if (asset) { + [self loadAsset:asset]; + } + else { + [LinphoneManager.instance.photoLibrary + enumerateGroupsWithTypes:ALAssetsGroupAll + usingBlock:^(ALAssetsGroup *group, BOOL *stop) { + [group enumerateAssetsWithOptions:NSEnumerationReverse + usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { + if([result.defaultRepresentation.url isEqual:imageUrl]) { + [self loadAsset:result]; + *stop = YES; + } + }]; + } + failureBlock:^(NSError *error) { + LOGE(@"Error: Cannot load asset from photo stream - %@", [error localizedDescription]); + }]; + } + }); } failureBlock:^(NSError *error) { LOGE(@"Can't read image"); }]; diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.m b/Classes/LinphoneUI/UIChatBubbleTextCell.m index 0aabc729c..b45ce2329 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.m +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.m @@ -359,12 +359,12 @@ static const CGFloat CELL_MESSAGE_Y_MARGIN = 52; // 44; LOGE(@"Can't read image"); dispatch_semaphore_signal(sema); }]; - }); - dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); + }); + dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); - size = [self getMediaMessageSizefromOriginalSize:originalImageSize withWidth:width]; - //This fixes the image being too small. I think the issue comes form the fact that the display is retina. This should probably be changed in the future. - size.height += CELL_MESSAGE_X_MARGIN; + size = [self getMediaMessageSizefromOriginalSize:originalImageSize withWidth:width]; + //This fixes the image being too small. I think the issue comes form the fact that the display is retina. This should probably be changed in the future. + size.height += CELL_MESSAGE_X_MARGIN; } } From 7d5fbbbd1101cb2f9a0a31f876ac86c94afa466c Mon Sep 17 00:00:00 2001 From: Benjamin Verdier Date: Thu, 21 Jun 2018 10:16:51 +0200 Subject: [PATCH 04/18] Image saving now in image picker --- Classes/ImagePickerView.m | 19 ++++- Classes/LinphoneManager.h | 1 + Classes/LinphoneUI/Base.lproj/UIChatCell.xib | 2 +- Classes/SideMenuView.m | 24 +++--- Classes/Utils/Utils.m | 77 +++++++++----------- 5 files changed, 65 insertions(+), 58 deletions(-) diff --git a/Classes/ImagePickerView.m b/Classes/ImagePickerView.m index c5ee92daf..5a9d34f50 100644 --- a/Classes/ImagePickerView.m +++ b/Classes/ImagePickerView.m @@ -20,7 +20,6 @@ #import #import #import -#import #import "ImagePickerView.h" #import "PhoneMainView.h" @@ -166,9 +165,21 @@ static UICompositeViewDescription *compositeDescription = nil; if (image == nil) { image = [info objectForKey:UIImagePickerControllerOriginalImage]; } - if (image != nil && imagePickerDelegate != nil) { - [imagePickerDelegate imagePickerDelegateImage:image info:info]; - } + if (image != nil) { + if (![info objectForKey:UIImagePickerControllerReferenceURL]) { + //Saving image. Supports picture only, no video + //Maybe add a completion target to send the saved image to, like self, and we would call it manually if the image was not taken. + UIImageWriteToSavedPhotosAlbum(image, self, @selector(savedImage:didFinishSavingWithError:contextInfo:), (__bridge void *)info); + } else { + [self savedImage:image didFinishSavingWithError:nil contextInfo:(__bridge void *)info]; + } + } +} + +- (void)savedImage:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo { + if (imagePickerDelegate != nil) { + [imagePickerDelegate imagePickerDelegateImage:image info:(__bridge NSDictionary *)contextInfo]; + } } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index 3b8650616..4bec1a351 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -226,6 +226,7 @@ typedef struct _LinphoneManagerSounds { @property (nonatomic, assign) BOOL speakerEnabled; @property (nonatomic, assign) BOOL bluetoothAvailable; @property (nonatomic, assign) BOOL bluetoothEnabled; +@property (readonly) ALAssetsLibrary *photoLibrary; @property (readonly) NSString* contactSipField; @property (readonly,copy) NSString* contactFilter; @property (copy) void (^silentPushCompletion)(UIBackgroundFetchResult); diff --git a/Classes/LinphoneUI/Base.lproj/UIChatCell.xib b/Classes/LinphoneUI/Base.lproj/UIChatCell.xib index 1a9c2b747..638f241be 100644 --- a/Classes/LinphoneUI/Base.lproj/UIChatCell.xib +++ b/Classes/LinphoneUI/Base.lproj/UIChatCell.xib @@ -67,7 +67,7 @@ - +