From 3bed6a18b04732ce448e49f3c1e88f6d02d766d8 Mon Sep 17 00:00:00 2001 From: Benjamin Verdier Date: Tue, 26 Jun 2018 10:13:35 +0200 Subject: [PATCH] Fix imagepicker not displaying after asking permission --- Classes/ImagePickerView.m | 64 ++++++++++++++++++--------------------- Classes/LinphoneManager.m | 2 -- Classes/SideMenuView.m | 8 ++--- 3 files changed, 34 insertions(+), 40 deletions(-) diff --git a/Classes/ImagePickerView.m b/Classes/ImagePickerView.m index 04e3a58e8..66be8d898 100644 --- a/Classes/ImagePickerView.m +++ b/Classes/ImagePickerView.m @@ -216,6 +216,7 @@ static UICompositeViewDescription *compositeDescription = nil; + (void)SelectImageFromDevice:(id)delegate atPosition:(UIView *)ipadPopoverView inView:(UIView *)ipadView { + LOGD(@"PUTAIN"); void (^block)(UIImagePickerControllerSourceType) = ^(UIImagePickerControllerSourceType type) { ImagePickerView *view = VIEW(ImagePickerView); view.sourceType = type; @@ -245,38 +246,7 @@ static UICompositeViewDescription *compositeDescription = nil; [PhoneMainView.instance changeCurrentView:view.compositeViewDescription]; } }; - - [PHPhotoLibrary authorizationStatus]; - PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus]; - - if (status == PHAuthorizationStatusNotDetermined) { - [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { - if(status != PHAuthorizationStatusAuthorized) { - [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Photo's permission", nil) message:NSLocalizedString(@"Photo not authorized", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Continue", nil] show]; - return; - } - DTActionSheet *sheet = [[DTActionSheet alloc] initWithTitle:NSLocalizedString(@"Select the source", nil)]; - if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { - [sheet addButtonWithTitle:NSLocalizedString(@"Camera", nil) - block:^() { - if([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] != AVAuthorizationStatusAuthorized ) { - [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Camera's permission", nil) message:NSLocalizedString(@"Camera not authorized", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Continue", nil] show]; - return; - } - block(UIImagePickerControllerSourceTypeCamera); - }]; - } - if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { - [sheet addButtonWithTitle:NSLocalizedString(@"Photo library", nil) - block:^() { - block(UIImagePickerControllerSourceTypePhotoLibrary); - }]; - } - [sheet addCancelButtonWithTitle:NSLocalizedString(@"Cancel", nil) block:nil]; - - [sheet showInView:PhoneMainView.instance.view]; - }]; - } else if (status == PHAuthorizationStatusAuthorized) { + if ([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusAuthorized) { DTActionSheet *sheet = [[DTActionSheet alloc] initWithTitle:NSLocalizedString(@"Select the source", nil)]; if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { [sheet addButtonWithTitle:NSLocalizedString(@"Camera", nil) @@ -298,8 +268,34 @@ static UICompositeViewDescription *compositeDescription = nil; [sheet showInView:PhoneMainView.instance.view]; } else { - [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Photo's permission", nil) message:NSLocalizedString(@"Photo not authorized", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Continue", nil] show]; - return; + [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { + dispatch_async(dispatch_get_main_queue(), ^{ + if ([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusAuthorized) { + DTActionSheet *sheet = [[DTActionSheet alloc] initWithTitle:NSLocalizedString(@"Select the source", nil)]; + if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { + [sheet addButtonWithTitle:NSLocalizedString(@"Camera", nil) + block:^() { + if([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] != AVAuthorizationStatusAuthorized ) { + [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Camera's permission", nil) message:NSLocalizedString(@"Camera not authorized", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Continue", nil] show]; + return; + } + block(UIImagePickerControllerSourceTypeCamera); + }]; + } + if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { + [sheet addButtonWithTitle:NSLocalizedString(@"Photo library", nil) + block:^() { + block(UIImagePickerControllerSourceTypePhotoLibrary); + }]; + } + [sheet addCancelButtonWithTitle:NSLocalizedString(@"Cancel", nil) block:nil]; + + [sheet showInView:PhoneMainView.instance.view]; + } else { + [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Photo's permission", nil) message:NSLocalizedString(@"Photo not authorized", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Continue", nil] show]; + } + }); + }]; } } diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 3896864cc..c3b290b66 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -2888,7 +2888,6 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { } + (void)setValueInMessageAppData:(id)value forKey:(NSString *)key inMessage:(LinphoneChatMessage *)msg { - dispatch_async(dispatch_get_main_queue(), ^{ NSMutableDictionary *appDataDict = [NSMutableDictionary dictionary]; const char *appData = linphone_chat_message_get_appdata(msg); if (appData) { @@ -2903,7 +2902,6 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { NSString *appdataJSON = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; linphone_chat_message_set_appdata(msg, [appdataJSON UTF8String]); [NSNotificationCenter.defaultCenter postNotificationName:kLinphoneMessageValueUpdated object:nil]; - }); } #pragma mark - LPConfig Functions diff --git a/Classes/SideMenuView.m b/Classes/SideMenuView.m index b94151454..8a57f81d8 100644 --- a/Classes/SideMenuView.m +++ b/Classes/SideMenuView.m @@ -113,6 +113,10 @@ image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); } + + [LinphoneManager.instance lpConfigSetString:phAssetId forKey:@"avatar"]; + _avatarImage.image = [LinphoneUtils selfAvatar]; + [LinphoneManager.instance loadAvatar]; // Dismiss popover on iPad if (IPAD) { @@ -120,10 +124,6 @@ } else { [PhoneMainView.instance.mainViewController hideSideMenu:NO]; } - - [LinphoneManager.instance lpConfigSetString:phAssetId forKey:@"avatar"]; - _avatarImage.image = [LinphoneUtils selfAvatar]; - [LinphoneManager.instance loadAvatar]; } @end