![](/img/trans.png)
[英]UIImagePickerViewController Cannot activate iOS11 's album permission BUT can load Photo and Videos
[英]In iOS11, you can not get permission through the “ALAssetsLibrary” or “PHPhotoLibrary” command
當我嘗試確定用戶是否具有打開相冊的權限時,xcode 告訴我這不起作用。
let authStatus = ALAssetsLibrary.authorizationStatus()
return authStatus != .restricted && authStatus != .denied
xcode 提醒我
'使用未解析的標識符'ALAssetsLibrary'
當我嘗試在 AppDelegate 上使用“PHPhotoLibrary”時
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 也告訴我
使用未解析的標識符“PHPhotoLibrary”
好的,我已經知道答案是什么了,一切正常后在swift文件頂部添加“導入照片”
“PHPhotoLibrary”按以下方式正確使用。
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
}}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.