当前位置: 首页>移动开发>正文

iOS14 -[PHPhotoLibrary presentLimitedLibraryPickerFromViewController-] crash的问题

之前适配 iOS 14 的相册权限遇到一些问题,这里记录以下。
当想要使用下面的API实现当用户选择限制模式(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...


https://www.xamrdz.com/mobile/44f1848595.html

相关文章: