加载图片的过程带有缓存处理,可以通过传入一个 PHImageRequestOptions 控制资源的输出尺寸等规格 PHImageRequestOptions:如上面所说,控制加载图片时的一系列参数 PHPhotoLibrary 您可以使用此对象对照片库中的对象集执行更改,例如,编辑资源元数据或内容,插入新资源或重新排列集合的成员,您还可以使用照片库对象来注册照片在内容或资源元数据和集合发生变化时发送的消息,并验证用户是否已授权您的应用访问照片内容(对PHPhotoLibrary } }) } 保存照片到特定相册 func savePhoto(image: UIImage, album: PHAssetCollection) { PHPhotoLibrary.shared } }) } 二、创建自定义相册 func createAssetCollection() -> Void{ PHPhotoLibrary.shared self.imageView.image = originImage; print("原图:\(originImage),图像信息:\(info)") } } PHPhotoLibrary
let viewController = self PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: viewController)复制代码 let viewController = self // 开始监听 PHPhotoLibrary.shared().register(viewController) // 结束监听 PHPhotoLibrary.shared = 1 case readWrite = 2 }复制代码 对应新增了一组获取/查看权限的 API: let level: PHAccessLevel = .readWrite // 获取权限 PHPhotoLibrary.requestAuthorization (for: level) { status in // Your code } // 查看权限 let status: PHAuthorizationStatus = PHPhotoLibrary.authorizationStatus
let viewController = self PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: viewController)复制代码 let viewController = self // 开始监听 PHPhotoLibrary.shared().register(viewController) // 结束监听 PHPhotoLibrary.shared = 1 case readWrite = 2 }复制代码 对应新增了一组获取/查看权限的 API: let level: PHAccessLevel = .readWrite // 获取权限 PHPhotoLibrary.requestAuthorization (for: level) { status in // Your code } // 查看权限 let status: PHAuthorizationStatus = PHPhotoLibrary.authorizationStatus
} break; default: break; } } 2.相册 这里针对于iOS8及其以后的系统相册检测方法,使用到的PHPhotoLibrary permissionGranted withNoPermission:(void (^)())noPermission{ PHAuthorizationStatus photoAuthStatus = [PHPhotoLibrary ) { case PHAuthorizationStatusNotDetermined: { //第一次提示用户授权 [PHPhotoLibrary
showSuccessWithStatus:@"保存成功"]; } } 方式二: NSError * error = nil; __block NSString * assetID = nil; [[PHPhotoLibrary
return status == 3; } + (NSInteger)authorizationStatus { if (iOS8Later) { return [PHPhotoLibrary dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [PHPhotoLibrary
53412675 之前的几篇博客我们分别给出了创建自定义相册、获取保存到相册中的图片,本篇博客就给出将图片保存到自定义相册中方法: 代码: NSError * error = nil; [[PHPhotoLibrary
查询相机权限:PHPhotoLibrary.authorizationStatus() 权限类型:PHAuthorizationStatus notDetermined 未申请 restricted 受限制 denied 已拒绝 authorized 已授权 limited 已授权有限库访问 请求相册权限,系统弹出授权申请提示: PHPhotoLibrary.requestAuthorization
将图片保存到自己创建相簿的步骤 1.判断用户授权情况 // 获取用户授权状态 PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus 对象(图片对象) __block NSString *assetLocalIdentifier = nil; // 如果想对"相册"进行修改(增删改), 那么修改代码必须放在[PHPhotoLibrary sharedPhotoLibrary]的performChanges方法的block中 [[PHPhotoLibrary sharedPhotoLibrary] performChanges: ; return; } [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ _block NSString *assetCollectionLocalIdentifier = nil; // 这个方法在主线程张中执行,等相簿创建完毕之后才会返回 [[PHPhotoLibrary
PHFetchResult<PHAsset *> *)createAsset{ NSError * error = nil; __block NSString * assetID = nil; [[PHPhotoLibrary
// 创建自己要创建的相册 NSError * error1 = nil; __block NSString * createCollectionID = nil; [[PHPhotoLibrary
savePhotoToCustomAlbumWithName核心源码如下: // 判断授权状态 [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus nil; // 保存相片到相机胶卷 __block PHObjectPlaceholder *createdAsset = nil; [[PHPhotoLibrary { NSSLog(@"保存自定义相册失败"); return; } [[PHPhotoLibrary
isHasPhotoLibraryAuthorityWithisShowAlert:(BOOL)showAlert block:(void (^)(id sender))block { PHAuthorizationStatus status = [PHPhotoLibrary 用户未作出明确选择的情况下自己主动请求了一次权限设置 [PHPhotoLibrary requestAuthorization
pickerViewController: PHPickerViewController = { var configuration = PHPickerConfiguration(photoLibrary: PHPhotoLibrary.shared
break; } 相册权限--iOS 8.0之后 导入头文件@import Photos; 检查是否有相册权限 PHAuthorizationStatus photoAuthorStatus = [PHPhotoLibrary [Uploading 144446-b8aca7ba38c5f8c0_695906.png . . .]获取相册权限 [PHPhotoLibrary requestAuthorization:^(
break; } 相册权限--iOS 8.0之后 导入头文件@import Photos; 检查是否有相册权限 PHAuthorizationStatus photoAuthorStatus = [PHPhotoLibrary PHAuthorizationStatusRestricted: NSLog(@"Restricted"); break; default: break; } 获取相册权限 [PHPhotoLibrary
break; } 相册权限--iOS 8.0之后 导入头文件@import Photos; 检查是否有相册权限 PHAuthorizationStatus photoAuthorStatus = [PHPhotoLibrary break; case PHAuthorizationStatusRestricted: NSLog(@"Restricted"); break; default: break;} 获取相册权限 [PHPhotoLibrary
为了发挥作用,这个视图控制器需要一个系统提供的PHPhotoLibrary类的实例(它是一个单例),以及一个我们自己的PhotoEditorEngine类的实例。 我们可以创建两个都有默认值的可变属性,就像这样: class PhotoEditorViewController: UIViewController { var library: PhotoLibrary = PHPhotoLibrary.shared
AVCaptureAudioDataOutput 视频——AVCaptureVideoDataOutput 生成视频文件——AVAssetWriter、AVAssetWriterInput 写入相册——ALAssetsLibrary、PHPhotoLibrary } } CFRelease(sampleBuffer); }); } } 写入相册——ALAssetsLibrary、PHPhotoLibrary NSError *error) { if (error) { [self showError:error]; } }]; iOS9.0以后 [PHPhotoLibrary ( PHAuthorizationStatus status ) { if (status == PHAuthorizationStatusAuthorized) { [[PHPhotoLibrary
= [self imageFromSampleBuffer:sampleBuffer]; PHAuthorizationStatus authorizationStatus = [PHPhotoLibrary authorizationStatus]; if (authorizationStatus == PHAuthorizationStatusAuthorized) { PHPhotoLibrary *library = [PHPhotoLibrary sharedPhotoLibrary]; [library performChanges:^{ [PHAssetChangeRequest [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { // 如果用户选择授权,则保存图片。