如何从相机胶卷中获取照片? [英] How to get photos from camera roll?

查看:167
本文介绍了如何从相机胶卷中获取照片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用ALAssetLibrary来获取相册和照片.这是我的代码:

I tried to use ALAssetLibrary to get albums and photos. This is my code:


void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
        if(result != NULL) {
            NSLog(@"See Asset: %@", result);
        }
    };

    void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) =  ^(ALAssetsGroup *group, BOOL *stop) {
        if(group != nil) {
            [group enumerateAssetsUsingBlock:assetEnumerator];
        }
    };

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [library enumerateGroupsWithTypes:ALAssetsGroupAll
                           usingBlock:assetGroupEnumerator
                         failureBlock: ^(NSError *error) {
                             NSLog(@"Failure");
                         }];

我在:[group enumarateAssetsUsingBlock:assetEnumerator]上获得了exc_bad_access,并且该组不是nil.

I'm getting exc_bad_access on : [group enumarateAssetsUsingBlock:assetEnumerator] and the group is not nil.

奇怪的是,如果我创建一个新项目,此代码将起作用,但是在我的旧项目中,它将无法起作用.

The strange thing is that this code is working if I create a new project, but in my old project it's not working.

SDK版本为iOS 4.3

SDK version is iOS 4.3

在iPhoneSimulator 4.3上测试

Tested on iPhoneSimulator 4.3

任何人都可以给我一个发生了什么的想法吗?

Can anyone could give me an ideea of what's happening?

谢谢.

推荐答案

当您在一个项目上崩溃而在另一个项目上崩溃时,确定设置和配置正确吗?

As you crash on the one project but not on the other, are you sure the settings and configurations are appropriate?

尤其是:

  • 检查TARGET_DEPLOYMENT_OS是否设置为ALAsset框架可用的最低版本.
  • 检查是否已包含所有请求的框架(即使链接器在忘记包含它的情况下也应发出警告)

此外,崩溃的详细信息(崩溃日志,异常详细信息……)将很有帮助.

Moreover, the details of the crash (crashlog, exception details, ...) would be helpful if any.

您还确定在枚举(可能是异步完成)结束之前未释放ALAssetLibrary吗?您的问题代码中没有release,但实际代码中可能没有release?

Also are you sure the ALAssetLibrary isn't released before the enumeration (which is probably done asynchnously) ends? There is no release in your code in your question but maybe there is one in your real code?

AFAIK,enumerateGroupsWithTypes:以异步方式在辅助线程上执行其块(请参见

AFAIK, enumerateGroupsWithTypes: executes its block on a secondary thread in an asynchrnous way (see this other question on SO), so that's probably your problem (you are trying to use a group that has been released from memory since you start your enumeration, you have to be sure the ALAssetLibrary is still in memory until the enumeration is done)

这篇关于如何从相机胶卷中获取照片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆