When I try to determine whether the user has permission to open the album, xcode told me that this does not work.
let authStatus = ALAssetsLibrary.authorizationStatus()
return authStatus != .restricted && authStatus != .denied
xcode remind me
‘Use of unresolved identifier 'ALAssetsLibrary’
when i try use 'PHPhotoLibrary' on AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
switch PHPhotoLibrary.authorizationStatus() {
case PHAuthorizationStatus.NotDetermined: // 用户暂未权限认证
print("PHAuthorizationStatus.NotDetermined")
// 权限认证
PHPhotoLibrary.requestAuthorization { (status:PHAuthorizationStatus) -> Void in
print(status)
}
case PHAuthorizationStatus.Restricted: // APP禁止使用相册权限认证
print("PHAuthorizationStatus.Restricted")
case PHAuthorizationStatus.Denied: // 用户拒绝使用相册
print("PHAuthorizationStatus.Denied")
print("请进入 设置 -> 隐私 -> 相册 开启权限")
// 设置-隐私-相册
case PHAuthorizationStatus.Authorized: // 用户允许使用相册
print("PHAuthorizationStatus.Authorized")
}
return true
}
xcode also told me
Use of unresolved identifier 'PHPhotoLibrary'
Ok,I have realized what is the answer, add the “import Photos” at the top of the swift file after everything is normal
"PHPhotoLibrary" is used correctly in the following way.