iOS中的资产库问题 - 5 [英] Asset Library issue in iOS - 5

查看:132
本文介绍了iOS中的资产库问题 - 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用资产库从url获取图片,我的代码是

i am using asset library for getting image from url , my code is

ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset){     
    ALAssetRepresentation *rep = [myasset defaultRepresentation];
    CGImageRef iref = [rep fullResolutionImage];
    UIImage *largeimage;

    if (iref) {
        largeimage = [UIImage imageWithCGImage:iref];
    }

    [self customeButtonCreated:self];

    NSData* thumbImageData = [[NSData alloc] initWithContentsOfFile:imagePath];
    btn1.frame = CGRectMake(x, y, WIDTH, HEIGHT);
    [btn1 setTag:tag];

    //[media_id addObject:[allKey objectAtIndex:0]];     
    [btnURl addObject:imagePath];

    UIImage *tempImage = [[UIImage alloc]initWithData:thumbImageData];
    [btn1 setImage:largeimage forState:UIControlStateNormal];
    btn1.imageView.contentMode = UIViewContentModeScaleAspectFit;           
    [tempImage release];

    [newView addSubview:btn1];
    [btn1 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [thumbImageData release];

    imgcount++;

    NSLog(@"Iamge count ---%d",imgcount);
    tag++;
};

ALAssetsLibraryAccessFailureBlock failureblock  = ^(NSError *myerror){
    NSLog(@"Cannot get image - %@",[myerror localizedDescription]);
};


if ([seprateArr count] == 2) {
    NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"assets-library://asset/asset.JPG?id=%@&ext=%@",[seprateArr objectAtIndex:0],[seprateArr objectAtIndex:1]]];
    ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
    [assetslibrary assetForURL:url resultBlock:resultblock failureBlock:failureblock];
}

它在ios中工作正常 - 4或以下,但在ios - 5中它未进入区块并显示错误

it is working fine in ios - 4 or below but in ios - 5 it is not entering in block and showing errir


无法获取图像 - 全局拒绝访问

任何解决方案?

推荐答案

这适用于我在ios 4.0以及ios 5中。

This works for me in ios 4.0 as well as ios 5.

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
NSString *photoName;
NSString *photoUrl;

 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
    void (^assetEnumerator)(ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) 
    {
        if(result != NULL) 
        {
            NSArray *arrKeys = [[result valueForProperty:ALAssetPropertyURLs]allKeys];             
            if([[result valueForProperty:ALAssetPropertyType]isEqualToString:ALAssetTypePhoto])
            {
                if([[UIDevice currentDevice] systemVersion]>=5.0))
                {
                    photoName = [[result defaultRepresentation]UTI];

                }
                else
                {
                    photoName = [[result defaultRepresentation]filename];

                }
                //Your code here
                photoUrl = [[result valueForProperty:ALAssetPropertyURLs]objectForKey:[arrKeys objectAtIndex:0]];

            }
        }
    };

    void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) =  ^(ALAssetsGroup *group, BOOL *stop) 
    {
        if(group != nil) 
        {
            [group enumerateAssetsUsingBlock:assetEnumerator];
        }
    };
    [library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:assetGroupEnumerator failureBlock:^(NSError *error){
        NSLog(@"%@",error);
    }];

    [pool release];

这篇关于iOS中的资产库问题 - 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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