【问题标题】:ALAssetRepresentation fullResolutionImage never returnsALAssetRepresentation fullResolutionImage 永远不会返回
【发布时间】:2012-11-15 18:05:19
【问题描述】:

我正在编写一个多线程应用程序,它需要在后台从 ALAssetsLibrary 批量上传照片。所以我有一个 NSOperation 子类,它通过资产的 URL 找到适当的 ALAsset 并将图像添加到上传队列。

在当前 ALAsset 的上传队列中,我需要从图像中获取元数据,但是我遇到了一个问题:-metadata 和 -fullResolutionImage 方法在调用ALA 资产。他们只是无限期地挂在那里。我尝试在 LLDB 中打印这些方法中的每一个的值,但它挂起了调试器,我最终杀死了 Xcode,信号 9 样式。这些方法在后台队列中被调用。

我正在 iPad 2 上测试这些。这是在 -assetForURL:resultBlock:failureBlock: 的成功块中找到 ALAsset 时将其添加到上传队列的方法:

- (void)addMediaToUploadQueue:(ALAsset *)media {
    @autoreleasepool {
        ALAssetRepresentation *defaultRepresentation = [media defaultRepresentation];
        CGImageRef fullResolutionImage = [defaultRepresentation fullResolutionImage];

        // Return if the user is trying to upload an image which has already been uploaded
        CGFloat scale = [defaultRepresentation scale];
        UIImageOrientation orientation = [defaultRepresentation orientation];

        UIImage *i = [UIImage imageWithCGImage:fullResolutionImage scale:scale orientation:orientation];
        if (![self isImageUnique:i]) return;

        NSDictionary *imageDictionary = [self dictionaryForAsset:media withImage:i];

        dispatch_async(self.background_queue, ^{
            NSManagedObjectContext *ctx = [APPDELEGATE createManagedObjectContextForThread];
            [ctx setUndoManager:nil];

            [ctx performBlock:^{
                ImageEntity *newImage = [NSEntityDescription insertNewObjectForEntityForName:@"ImageEntity"
                                                                    inManagedObjectContext:ctx];

                [newImage updateWithDictionary:imageDictionary
                         inManagedObjectContext:ctx];

                [ctx save:nil];

                [APPDELEGATE saveContext];

                dispatch_async(dispatch_get_main_queue(), ^{
                    [self.fetchedResultsController performFetch:nil];
                });

                    if (!currentlyUploading) {
                        currentlyUploading = YES;
                        [self uploadImage:newImage];
                    }
            }];
        });
    }
}

【问题讨论】:

    标签: objective-c ios alassetslibrary


    【解决方案1】:

    我也遇到了类似的问题,我正在扯头发试图弄明白。

    结果我以为我为 ALAssetsLibrary 设置了一个单例,但我的代码没有正确调用它,并且一些 ALAsset 返回一个空的“fullResolutionImage”

    在我所有的 NSLogs 中,我一定错过了来自 Xcode 的最重要的信息:

    “在其拥有的 ALAssetsLibrary 的生命周期之后访问 ALAssetPrivate 的尝试无效”

    点击此链接

    http://www.daveoncode.com/2011/10/15/solve-xcode-error-invalid-attempt-to-access-alassetprivate-past-the-lifetime-of-its-owning-alassetslibrary/

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2011-04-08
      • 2019-11-15
      • 2011-07-25
      • 1970-01-01
      • 2012-10-02
      • 2013-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多