【问题标题】:ALAssetsLibrary-CustomPhotoAlbum ios 8ALAssetsLibrary-CustomPhotoAlbum ios 8
【发布时间】:2014-12-21 00:40:54
【问题描述】:

更新/改写的问题:

在我的项目中,我使用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]);
    }
}];

它似乎改变了完成/失败阻止过程,我想不通。

我需要做什么才能将它们链接到图书馆?

任何帮助将不胜感激。

更新 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];

【问题讨论】:

    标签: ios photo alassetslibrary


    【解决方案1】:

    虽然我确实认为 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];
    

    希望这对某人有所帮助,尽管这个问题被否决是一种耻辱。

    【讨论】:

      猜你喜欢
      • 2014-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多