gpt4 book ai didi

ios - 将图像保存到特定相册,但限制保存到相机胶卷文件夹中

转载 作者:行者123 更新时间:2023-11-29 06:01:34 28 4
gpt4 key购买 nike

我在这里需要一点帮助,我有一种方法可以将 UIImage 保存到我的自定义图像文件夹中,但图像也保存到相机胶卷文件夹中,这是我不想要的。

请问,有人可以建议我如何限制保存到相机胶卷文件夹中吗?

NSString *albumName = @"myApp";
void (^saveBlock)(PHAssetCollection *assetCollection) = ^void(PHAssetCollection *assetCollection) {
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{

PHAssetChangeRequest *assetChangeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
PHAssetCollectionChangeRequest *assetCollectionChangeRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:assetCollection];
[assetCollectionChangeRequest addAssets:@[[assetChangeRequest placeholderForCreatedAsset]]];

} completionHandler:^(BOOL success, NSError *error) {
if (!success) {
NSLog(@"Error creating asset: %@", error);
}
}];
};

PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
fetchOptions.predicate = [NSPredicate predicateWithFormat:@"localizedTitle = %@", albumName];
PHFetchResult *fetchResult = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:fetchOptions];

if (fetchResult.count > 0) {
saveBlock(fetchResult.firstObject);
} else {
__block PHObjectPlaceholder *albumPlaceholder;
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{

PHAssetCollectionChangeRequest *changeRequest = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:albumName];
albumPlaceholder = changeRequest.placeholderForCreatedAssetCollection;

} completionHandler:^(BOOL success, NSError *error) {
if (success) {
PHFetchResult *fetchResult = [PHAssetCollection fetchAssetCollectionsWithLocalIdentifiers:@[albumPlaceholder.localIdentifier] options:nil];
if (fetchResult.count > 0) {
saveBlock(fetchResult.firstObject);
}
} else {
NSLog(@"Error creating album: %@", error);
}
}];
}
NSLog(@"Count : %lu",(unsigned long)[arrForHereLoImages count]);

最佳答案

相机胶卷包含所有设备图片。这是 iOS 设计的。你无法阻止这一点。
您的图像不会保存两次,而是实际保存在相机胶卷中并在您的自定义相册中引用。

关于ios - 将图像保存到特定相册,但限制保存到相机胶卷文件夹中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54627541/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com