我试图创建一个Photo"文件夹"并返回指向它的指针。这可能吗?下面是我到目前为止的代码。感谢。
- (PHCollectionList *) CreatePhotoFolder: (NSString *) folderName
{
[[PHPhotoLibrary sharedPhotoLibrary]
performChanges:^{
// Create the folder
[PHCollectionListChangeRequest creationRequestForCollectionListWithTitle: folderName];
}
completionHandler:^(BOOL success, NSError *error) {
if (!success) { NSLog(@"Error creating Folder: %@", error); }
else {
// How do I return the new PHCollectionList* for the new folder?
}
}
];
}
答案 0 :(得分:0)
您需要先按占位符获取本地ID。
__block NSString * localId;
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetCollectionChangeRequest *assetCollectionChangeRequest = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:@"XD"];
localId = [[assetCollectionChangeRequest placeholderForCreatedAssetCollection] localIdentifier];
} completionHandler:^(BOOL success, NSError *error) {
if (!success) {
NSLog(@"Error creating album: %@", error);
} else {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:localId forKey:@"collection"];
[prefs synchronize];
}
}];
然后通过此本地ID获取PHAssetCollection
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString* colletionId = [prefs stringForKey:@"collection"];
if(colletionId == nil) {
colletionId = @"";
}
PHFetchResult *result = [PHAssetCollection fetchAssetCollectionsWithLocalIdentifiers:@[colletionId] options:nil];
self.assetCollection = [result firstObject];