Fix imagepicker not displaying after asking permission

This commit is contained in:
Benjamin Verdier 2018-06-26 10:13:35 +02:00
parent 5cacbd50c1
commit 3bed6a18b0
3 changed files with 34 additions and 40 deletions

View file

@ -216,6 +216,7 @@ static UICompositeViewDescription *compositeDescription = nil;
+ (void)SelectImageFromDevice:(id<ImagePickerDelegate>)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];
}
});
}];
}
}

View file

@ -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

View file

@ -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