OC获取并创建自定义相册

saonian 发布于 02-15 08:13 298 点击
```oc - (PHAssetCollection *)createdCollection { // 查询是否创建过相册 PHFetchResult<PHAssetCollection *> *result = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil]; // 获取APP名称 NSString *appName = [NSBundle mainBundle].infoDictionary[@"CFBundleDisplayName"]; // 遍历相册查看是否有和当前APP同名的相册 for (PHAssetCollection *collection in result) { if ([collection.localizedTitle isEqualToString:appName]) { return collection; } } // 创建自定义相册 __block NSString *identifier = nil; NSError *error = nil; [[PHPhotoLibrary sharedPhotoLibrary] performChangesAndWait:^{ identifier = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:appName].placeholderForCreatedAssetCollection.localIdentifier; } error:&error]; if (error) return nil; return [PHAssetCollection fetchAssetCollectionsWithLocalIdentifiers:@[identifier] options:nil].firstObject; } ```
0 评论

请登录后发表评论

saonian

all or nothing, now or never.

文章
回复
粉丝