ios - ALAssetsLibrary-自定义相册 ios 8

标签 ios photo alassetslibrary

更新/改写问题:

在我的项目中,我使用 ALAssetsLibrary-CustomPhotoAlbum 。虽然它在 iOS 7 上运行良好,但我从未注意到在为 iOS 8 编码时,它最终被破坏了。无法重新创建已删除的同名文件夹。

如果它作为一个新进程启动,它将创建文件夹,如果您打开应用程序并请求照片许可。

如果我手动创建文件夹,我当前的代码仍然会将照片保存到所述文件夹:

    [self.library saveImage:image toAlbum:@"NamedAlbum" withCompletionBlock:^(NSError *error) {
        if (error!=nil) {
            NSLog(@"Big error: %@", [error description]);
        }
    }];

我坚持的是以下内容:

[self.library saveImage:image toAlbum:@"NamedAlbum" completion:nil failure:^(NSError *error) {
    if (error!=nil) {
        NSLog(@"Big error: %@", [error description]);
    }
}];

它似乎改变了完成/失败 block 过程,我无法弄明白。

我需要做什么才能将它们链接到库?

如有任何帮助,我们将不胜感激。

12 月 22 日更新 似乎我在发布我的答案时超前了,这只是有时有效。将继续挖掘。

// The completion block to be executed after image taking action process done
void (^completion)(NSURL *, NSError *) = ^(NSURL *assetURL, NSError *error) {
    if (error) NSLog(@"!!!ERROR,  write the image data to the assets library (camera roll): %@",
                     [error description]);
    NSLog(@"*** URL %@ | %@ || type: %@ ***", assetURL, image, [assetURL class]);

};

void (^failure)(NSError *) = ^(NSError *error) {
    if (error == nil) return;
    NSLog(@"!!!ERROR, failed to add the asset to the custom photo album: %@", [error description]);
};

[self.assetsLibrary saveImage:image
                      toAlbum:albumName
                   completion:completion
                      failure:failure];

最佳答案

虽然我确实相信 SDK 中存在错误。我下面的内容似乎在我的 6+ 上运行良好。

这可能不是“正确”的方法,但它是所提供的示例中有效的方法。

NSURL *imageURL = receivedURL;
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
NSString *albumName = @"NamedAlbum";

// The completion block to be executed after image taking action process done
void (^completion)(NSURL *, NSError *) = ^(NSURL *assetURL, NSError *error) {

    if (error) NSLog(@"!!!ERROR,  write the image data to the assets library (camera roll): %@",
                     [error description]);
    NSLog(@"*** URL %@ | %@ || type: %@ ***", assetURL, image, [assetURL class]);

};

void (^failure)(NSError *) = ^(NSError *error) {
    if (error == nil) return;
    NSLog(@"!!!ERROR, failed to add the asset to the custom photo album: %@", [error description]);
};

[self.library saveImage:image
                      toAlbum:albumName
                   completion:completion
                      failure:failure];

希望这对某人有帮助,尽管很遗憾这个问题被否决了。

关于ios - ALAssetsLibrary-自定义相册 ios 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27585750/

相关文章:

objective-c - 绘制阴影以获得透明形状

ios - 如何修复链接器错误 "Undefined symbols for architecture i386 from: "_current_task""?

ios - 如何创建像照片应用程序一样的延时视频?

iphone - iOS - ALAssetsLibrary 使用的缓存数据未更新

android - 使用 HTML、Javascript 进行移动开发的最佳平台。除了 native 应用程序开发

ios - 获取游戏请求ID/获取Facebook游戏请求通知内容

php - Image Carousel 后端 PHP Mysql

facebook - 可以在您的网络应用程序中使用 Facebook 照片吗?

ios - 使用 AssetLibraryPhotosViewer 访问照片

objective-c - ALAssetRepresentation fullResolutionImage 永远不会返回