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’
xcode screenshot
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.
func AlbumPermissions() -> Int { // Photos Permissions
switch PHPhotoLibrary.authorizationStatus() {
case .notDetermined:// User has not permitted the permission
print("PHAuthorizationStatus.NotDetermined")
PHPhotoLibrary.requestAuthorization { (status:PHAuthorizationStatus) -> Void in
print(status)
}
return 0
case .restricted:// APP reject the permission of Photos
print("PHAuthorizationStatus.Restricted")
return 1
case .denied:// Users denied the Photos permission
print("PHAuthorizationStatus.Denied")
print("Please go to Setting to turn on the Photos permission.")
return 2
case .authorized: // User permit the Photos permission.
print("PHAuthorizationStatus.Authorized")
return 3
}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With