user3279258
user3279258

Reputation: 37

assetForURL with ios 5.0 doesn't work with device

- (void)thumbnail:(NSNumber *)index{

    __block NSNumber *number = [NSNumber numberWithInt:[index intValue]];

    ALAssetsLibrary *library = [ALAssetsLibrary sharedALAssetsLibrary];

ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
        CGImageRef iref = [myasset thumbnail];
        if (iref) {
        [delegate thumbnailDidLoad:[UIImage imageWithCGImage:iref] withIndex:number];
        }
     NSLog(@"RESSSSSSSSSSSSSSSSSSSSSSSSSSSSSULT");
};

    ALAssetsLibraryAccessFailureBlock failureblock  = ^(NSError *myerror)
    {
        NSLog(@"Error, can't get image - %@",[myerror localizedDescription]);
    };
    NSString *mediaurl =  @"assets-library://asset/asset.JPG?id=5AF4118C-947D-4097-910E-47E19553039C&ext=JPG";

    NSURL *asseturl = [NSURL URLWithString:mediaurl];
    [library assetForURL:asseturl resultBlock:resultblock failureBlock:failureblock];
    NSLog(@"asseturl %@",asseturl);
}

Here is my code and i have issue with my blocks - they works under simulator 5.0 but they don't work under device at all, it doesn't stop on break points and NSLogs don't work. With simulator all work correctly. Notice: CLAuthorizationStatus == kCLAuthorizationStatusAuthorized

Upvotes: 1

Views: 980

Answers (2)

troppoli
troppoli

Reputation: 558

Make sure that this whole function - (void)thumbnail:(NSNumber *)index... is either executed from the main thread or you are sure that the user has authorized your app to use location services. If you call it in the background and you don't yet have authorization, then the user will never be prompted for approval and neither the result nor failure blocks will be called.

Upvotes: 1

holtmann
holtmann

Reputation: 6303

as of iOS5 assetForURL works async. Make sure you call

    [delegate thumbnailDidLoad:[UIImage imageWithCGImage:iref] withIndex:number];

on the main thread. This is easiest accomplished by using dispatch_async on the main queue.

Cheers,

Hendrik

Upvotes: 0

Related Questions