之前適配 iOS 14 的相冊權限遇到一些問題祈搜,這里記錄以下枣接。
當想要使用下面的API實現(xiàn)當用戶選擇限制模式(PHAuthorizationStatusLimited)時萌业,通過顯示限制模式的圖像選擇器窑业,提示用戶更新其已選擇展示的照片資源:
//
// PHPhotoLibrary+PhotosUISupport.h
// PhotosUI
//
// Copyright ? 2020 Apple Inc. All rights reserved.
//
#import <Photos/Photos.h>
@class UIViewController;
API_AVAILABLE_BEGIN(ios(14))
API_UNAVAILABLE_BEGIN(macos, tvos, watchos)
NS_ASSUME_NONNULL_BEGIN
@interface PHPhotoLibrary (PhotosUISupport)
/**
@abstract Prompt the user to update their limited library selection by presenting the limited library image picker when the user has opted into limited library access mode (see \c PHAuthorizationStatusLimited )
@param controller The view controller that is used to present the limited library picker.
@discussion Use this API when the user has enabled limited photo library access to present the limited library picker and give the user a way to update their selection. If the user has not enabled limited library access mode for this application, then this method will do nothing. This should be used when disabling the automatic limited library alert prompt (by adding \c PHPhotoLibraryPreventAutomaticLimitedAccessAlert = \c YES to the application's Info.plist).
Any changes applied to the limited library selection by the user will trigger a \c PHPhotoLibraryChangeObserver update that can be used to observe the changes to the selection.
*/
- (void)presentLimitedLibraryPickerFromViewController:(UIViewController *)controller;
@end
NS_ASSUME_NONNULL_END
API_UNAVAILABLE_END // (macos, tvos, watchos)
API_AVAILABLE_END // (ios(14))
理論上翔怎,只需要在控制器中這么寫:
#import <PhotosUI/PHPhotoLibrary+PhotosUISupport>
if (@available(iOS 14.0, *)) {
[[PHPhotoLibrary sharedPhotoLibrary] presentLimitedLibraryPickerFromViewController:self];
}
但是卻crash了...
-[PHPhotoLibrary presentLimitedLibraryPickerFromViewController:]: unrecognized selector sent to instance 0x2804243c0
最終找到原因,是因為沒有在項目中鏈接 PhotosUI.framework...