当我尝试确定用户是否有权打开相册时,xcode 告诉我这不起作用。
let authStatus = ALAssetsLibrary.authorizationStatus()
return authStatus != .restricted && authStatus != .denied
xcode 提醒我
'使用未解析的标识符'ALAssetsLibrary'</p>
当我尝试在 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”