views:

35

answers:

2

i am trying to access videos in iPhone library using AssetsLibrary Framework with the help of following code...but when i run the application the code is not working...the array assets is still empty?? what am i doing wrong??

btw my iPhone is a 3G upgraded to iPhone 4.1.(but assets framework is not giving any error)

NSMutableArray *assets = [[NSMutableArray alloc]init];
ALAssetsLibrary *library =[[ALAssetsLibrary alloc]init];

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

            }
        };

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



        };

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

Double Init: NSMutableArray *assets = [[NSMutableArray alloc]init]; ALAssetsLibrary *library =[[ALAssetsLibrary alloc]init];

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

        }
    };

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



    };

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

Hi, the 4.1 upgrade seems to have 'broken' some of the image picker examples, observe the following lines, which run after the code you have posted:

NSUInteger groupTypes = ALAssetsGroupAlbum | ALAssetsGroupEvent | ALAssetsGroupFaces;
[assetsLibrary enumerateGroupsWithTypes:groupTypes usingBlock:listGroupBlock failureBlock:failureBlock];

This gives zero assets both on my 4.1 iPhone and simulator. However changing the groupTypes helps, so set

 NSUInteger groupTypes = ALAssetsGroupAll;

and you should start seeing some assets.

Thomas