Skip to content

Commit

Permalink
Adding messenger inspired iOS 14 limited permission info help in albu…
Browse files Browse the repository at this point in the history
…m controller (#1676)
  • Loading branch information
timbrandin authored Nov 10, 2021
1 parent 633769b commit cd26484
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 4 deletions.
68 changes: 67 additions & 1 deletion ios/QBImagePicker/QBImagePicker/QBAlbumsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "QBAlbumsViewController.h"
#import <Photos/Photos.h>
#import <PhotosUI/PhotosUI.h>

// Views
#import "QBAlbumCell.h"
Expand All @@ -20,6 +21,14 @@ static CGSize CGSizeScale(CGSize size, CGFloat scale) {
return CGSizeMake(size.width * scale, size.height * scale);
}

static bool isLimitedPermission() {
if (@available(iOS 14, *)) {
PHAuthorizationStatus accessLevel = [PHPhotoLibrary authorizationStatusForAccessLevel: PHAccessLevelReadWrite];
return accessLevel == PHAuthorizationStatusLimited;
}
return false;
}

@interface QBImagePickerController (Private)

@property (nonatomic, strong) NSBundle *assetBundle;
Expand Down Expand Up @@ -259,21 +268,78 @@ - (void)updateControlState
self.doneButton.enabled = [self isMinimumSelectionLimitFulfilled];
}

#pragma mark - Manage Limited Permission

-(void)managePermissionAction:(id)sender
{
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTableInBundle(@"permission.title", @"QBImagePicker", self.imagePickerController.assetBundle, nil) message:nil preferredStyle:UIAlertControllerStyleActionSheet];

[actionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTableInBundle(@"permission.cancel", @"QBImagePicker", self.imagePickerController.assetBundle, nil) style:UIAlertActionStyleCancel handler:nil]];

[actionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTableInBundle(@"permission.choose_more", @"QBImagePicker", self.imagePickerController.assetBundle, nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
// Open limited permission picker.
if (@available(iOS 14, *)) {
[[PHPhotoLibrary sharedPhotoLibrary] presentLimitedLibraryPickerFromViewController:self];
}
}]];

[actionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTableInBundle(@"permission.change_settings", @"QBImagePicker", self.imagePickerController.assetBundle, nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
// Open application settings.
UIApplication *application = [UIApplication sharedApplication];
NSURL *URL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[application openURL:URL options:@{} completionHandler:nil];
}]];

// Present action sheet.
[self presentViewController:actionSheet animated:YES completion:nil];
}

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
return isLimitedPermission() ? 2 : 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (isLimitedPermission() && section == 0) {
return 1;
}
return self.assetCollections.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (isLimitedPermission()) {
if (indexPath.section == 0) {
CGRect frame = [tableView rectForRowAtIndexPath:indexPath];
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.tag = indexPath.row;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell setBackgroundColor:[UIColor colorWithRed: 0.97 green: 0.97 blue: 0.97 alpha: 1.00]];

UIButton *manageButton = [UIButton buttonWithType:UIButtonTypeSystem];
[manageButton setBackgroundColor:[UIColor colorWithRed: 0.87 green: 0.87 blue: 0.87 alpha: 1.00]];
[manageButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[manageButton addTarget:self action:@selector(managePermissionAction:) forControlEvents:UIControlEventTouchUpInside];
manageButton.layer.cornerRadius = 12;
manageButton.contentEdgeInsets = UIEdgeInsetsMake(4, 12, 4, 12);
[manageButton setTitle:NSLocalizedStringFromTableInBundle(@"permission.manage", @"QBImagePicker", self.imagePickerController.assetBundle, nil) forState:UIControlStateNormal];
[manageButton sizeToFit];
[cell setAccessoryView:manageButton];

UILabel *helpText = [[UILabel alloc] initWithFrame:CGRectMake(16,0,cell.contentView.frame.size.width - manageButton.frame.size.width + 24, frame.size.height)];
helpText.font = [UIFont systemFontOfSize:13];
[helpText setNumberOfLines:2];
helpText.text = NSLocalizedStringFromTableInBundle(@"permission.help", @"QBImagePicker", self.imagePickerController.assetBundle, nil);

[cell.contentView addSubview:helpText];

return cell;
}
}

QBAlbumCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AlbumCell" forIndexPath:indexPath];
cell.tag = indexPath.row;
cell.borderWidth = 1.0 / [[UIScreen mainScreen] scale];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@

"assets.toolbar.item-selected" = "%ld Element ausgewählt";
"assets.toolbar.items-selected" = "%ld Elemente ausgewählt";

"permission.help" = "Sie haben einer begrenzten Anzahl ausgewählter Fotos und Videos die Erlaubnis erteilt.";
"permission.manage" = "VERWALTEN";
"permission.title" = "Um auf alle Ihre Fotos in der App zuzugreifen, geben Sie in den Geräteeinstellungen Zugriff auf Ihre vollständige Bibliothek.";
"permission.choose_more" = "Weitere Fotos auswählen";
"permission.change_settings" = "Einstellungen ändern";
"permission.cancel" = "Abbrechen";
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@

"assets.toolbar.item-selected" = "%ld Item Selected";
"assets.toolbar.items-selected" = "%ld Items Selected";

"permission.help" = "You have given permission to a limited number of selected photos and videos.";
"permission.manage" = "MANAGE";
"permission.title" = "To access all your photos in the app, give access to your full library in the device settings.";
"permission.choose_more" = "Select More Photos";
"permission.change_settings" = "Change Settings";
"permission.cancel" = "Cancel";
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@

"assets.toolbar.item-selected" = "%ld items seleccionados";
"assets.toolbar.items-selected" = "%ld items seleccionados";

"permission.help" = "Ha otorgado permiso a un número limitado de fotos y videos seleccionados.";
"permission.manage" = "ADMINISTRAR";
"permission.title" = "Para acceder a todas sus fotos en la aplicación, dé acceso a su biblioteca completa en la configuración del dispositivo.";
"permission.choose_more" = "Seleccionar más fotos";
"permission.change_settings" = "Cambiar configuración";
"permission.cancel" = "Cancelar";
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@

"assets.toolbar.item-selected" = "%ld Élément Sélectionné";
"assets.toolbar.items-selected" = "%ld Éléments Sélectionnés";

"permission.help" = "Vous avez autorisé un nombre limité de photos et de vidéos sélectionnées.";
"permission.manage" = "GÉRER";
"permission.title" = "Pour accéder à toutes vos photos dans l'application, donnez accès à votre bibliothèque complète dans les paramètres de l'appareil.";
"permission.choose_more" = "Sélectionner plus de photos" ;
"permission.change_settings" = "Modifier les paramètres" ;
"permission.cancel" = "Annuler" ;
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@
"assets.footer.photos-and-videos" = "%ld Foto, %ld Video";

"assets.toolbar.item-selected" = "%ld Elemento Selezionato";
"assets.toolbar.items-selected" = "%ld Elementi Selezionati";
"assets.toolbar.items-selected" = "%ld Elementi Selezionati";

"permission.help" = "Hai autorizzato un numero limitato di foto e video selezionati.";
"permission.manage" = "GESTISCI";
"permission.title" = "Per accedere a tutte le tue foto nell'app, concedi l'accesso alla tua libreria completa nelle impostazioni del dispositivo.";
"permission.choose_more" = "Seleziona altre foto";
"permission.change_settings" = "Cambia impostazioni";
"permission.cancel" = "Annulla";
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@

"assets.toolbar.item-selected" = "%ld 項目を選択中";
"assets.toolbar.items-selected" = "%ld 項目を選択中";

"permission.help" = "選択した限られた数の写真とビデオに許可を与えました。";
"permission.manage" = "MANAGE";
"permission.title" = "アプリ内のすべての写真にアクセスするには、デバイス設定でライブラリ全体へのアクセスを許可します。";
"permission.choose_more" = "写真をもっと選択";
"permission.change_settings" = "設定の変更";
"permission.cancel" = "キャンセル";
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@

"assets.toolbar.item-selected" = "%ld 선택된 아이템";
"assets.toolbar.items-selected" = "%ld 선택된 아이템";

"permission.help" = "선택한 사진 및 비디오의 제한된 수에 대한 권한을 부여했습니다.";
"permission.manage" = "관리";
"permission.title" = "앱에 있는 모든 사진에 접근하려면 기기 설정에서 전체 보관함에 접근 권한을 부여하십시오.";
"permission.choose_more" = "추가 사진 선택";
"permission.change_settings" = "설정 변경";
"permission.cancel" = "취소";
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@

"assets.toolbar.item-selected" = "%ld zaznaczona rzecz";
"assets.toolbar.items-selected" = "Zaznaczonych rzeczy: %ld";

"permission.help" = "Zezwolono na ograniczoną liczbę wybranych zdjęć i filmów.";
"permission.manage" = "ZARZĄDZAJ";
"permission.title" = "Aby uzyskać dostęp do wszystkich swoich zdjęć w aplikacji, zezwól na dostęp do pełnej biblioteki w ustawieniach urządzenia.";
"permission.choose_more" = "Wybierz więcej zdjęć";
"permission.change_settings" = "Zmień ustawienia";
"permission.cancel" = "Anuluj";
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@
"assets.footer.photos-and-videos" = "%ld Fotos, %ld Vídeos";

"assets.toolbar.item-selected" = "%ld Item Selecionado";
"assets.toolbar.items-selected" = "%ld Itens Selecionados";
"assets.toolbar.items-selected" = "%ld Itens Selecionados";

"permission.help" = "Você deu permissão a um número limitado de fotos e vídeos selecionados.";
"permission.manage" = "GERENCIAR";
"permission.title" = "Para acessar todas as suas fotos no aplicativo, dê acesso à sua biblioteca completa nas configurações do dispositivo.";
"permission.choose_more" = "Selecionar mais fotos";
"permission.change_settings" = "Alterar configurações";
"permission.cancel" = "Cancelar";
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@

"assets.toolbar.item-selected" = "%ld Element Selectat";
"assets.toolbar.items-selected" = "%ld Elemente Selectate";

"permission.help" = "Ați acordat permisiunea unui număr limitat de fotografii și videoclipuri selectate.";
"permission.manage" = "GESTIONARE";
"permission.title" = "Pentru a vă accesa toate fotografiile din aplicație, acordați acces la biblioteca completă în setările dispozitivului.";
"permission.choose_more" = "Selectați mai multe fotografii";
"permission.change_settings" = "Schimbați setările";
"permission.cancel" = "Anulați";
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@

"assets.toolbar.item-selected" = "%ld Элемент выбран";
"assets.toolbar.items-selected" = "%ld Элементы выбраны";

"permission.help" = "Вы дали разрешение на ограниченное количество выбранных фотографий и видео.";
"permission.manage" = "УПРАВЛЕНИЕ";
"permission.title" = "Чтобы получить доступ ко всем своим фотографиям в приложении, предоставьте доступ к полной библиотеке в настройках устройства.";
"permission.choose_more" = "Выбрать больше фотографий";
"permission.change_settings" = "Изменить настройки";
"permission.cancel" = "Отменить";
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@

"assets.toolbar.item-selected" = "%ld Markerad Objekt";
"assets.toolbar.items-selected" = "%ld Markerade Objekt";

"permission.help" = "Du har gett åtkomst till ett begränsat antal utvalda bilder och videor.";
"permission.manage" = "HANTERA";
"permission.title" = "För att komma åt alla dina foton i appen, ge åtkomst till ditt fulla bibliotek i enhetens inställningar.";
"permission.choose_more" = "Välj fler foton";
"permission.change_settings" = "Ändra inställningar";
"permission.cancel" = "Avbryt";
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@

"assets.toolbar.item-selected" = "%ld Adet Seçildi";
"assets.toolbar.items-selected" = "%ld Adet Seçildi";

"permission.help" = "Sınırlı sayıda seçili fotoğraf ve videoya izin verdiniz.";
"permission.manage" = "YÖNET";
"permission.title" = "Uygulamadaki tüm fotoğraflarınıza erişmek için cihaz ayarlarından tam kitaplığınıza erişim izni verin.";
"permission.choose_more" = "Daha Fazla Fotoğraf Seç";
"permission.change_settings" = "Ayarları Değiştir";
"permission.cancel" = "İptal";
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@

"assets.toolbar.item-selected" = "Вибрано %ld Елемент";
"assets.toolbar.items-selected" = "Вибрано %ld Елементи";

"permission.help" = "Ви дали дозвіл на обмежену кількість вибраних фотографій і відео.";
"permission.manage" = "КЕРУВАТИ";
"permission.title" = "Щоб отримати доступ до всіх своїх фотографій у програмі, надайте доступ до повної бібліотеки в налаштуваннях пристрою.";
"permission.choose_more" = "Вибрати більше фотографій";
"permission.change_settings" = "Змінити налаштування";
"permission.cancel" = "Скасувати";
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@

"assets.toolbar.item-selected" = "选择了%ld项";
"assets.toolbar.items-selected" = "选择了%ld项";

"permission.help" = "您已授予有限数量的选定照片和视频的权限。";
"permission.manage" = "MANAGE";
"permission.title" = "要访问您在应用程序中的所有照片,请在设备设置中授予访问您的完整图库的权限。";
"permission.choose_more" = "选择更多照片";
"permission.change_settings" = "更改设置";
"permission.cancel" = "取消";
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@
"assets.footer.photos-and-videos" = "共%ld 張照片, %ld 個視頻";

"assets.toolbar.item-selected" = "選擇了%ld項";
"assets.toolbar.items-selected" = "選擇了%ld項";
"assets.toolbar.items-selected" = "選擇了%ld項";

"permission.help" = "您已授予有限數量的選定照片和視頻的權限。";
"permission.manage" = "管理";
"permission.title" = "要訪問您在應用程序中的所有照片,請在設備設置中授予訪問您的完整圖庫的權限。";
"permission.choose_more" = "選擇更多照片";
"permission.change_settings" = "更改設置";
"permission.cancel" = "取消";

0 comments on commit cd26484

Please sign in to comment.