Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Get all image assets from iPhone Image Gallery

    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 467
    Comment on it

    Write following code in .h file
    Add first the assets library framework from BuildPhase -> Link Binary with libraries
    import framework in .h

    AssetsLibrary/AssetsLibrary.h


    Declare properties

    @property (nonatomic, retain) ALAssetsGroup assetsGroup;
    @property (nonatomic,strong)NSMutableArray
    assetsArray;
    @property (nonatomic, retain) ALAssetsLibrary* assetLibrary;

    Write this code in .m file // Call this below mentioned function in your viewWillAppear
    -(void)getAllPictures
    {
    self.assetsArray = [[NSMutableArray alloc]init];
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    self.assetLibrary = library;
    NSMutableArray *groups = [NSMutableArray array];
    [assetLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
    if (group) {
    [groups addObject:group];
    } else {
    // this is the end
    [self displayPickerForGroup:[groups objectAtIndex:0]];
    }
    } failureBlock:^(NSError *error) {
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[NSString stringWithFormat:@"Album Error: %@ - %@", [error localizedDescription], [error localizedRecoverySuggestion]] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show];

        NSLog(@"A problem occurred %@", [error description]);
        // an error here means that the asset groups were inaccessible.
        // Maybe the user or system preferences refused access.
    }];
    

    } //=========================================================================== - (void)displayPickerForGroup:(ALAssetsGroup *)group
    {
    self.assetsGroup = group;
    [self.assetsGroup setAssetsFilter:[ALAssetsFilter allAssets]];
    [self preparePhotos];
    }
    //=========================================================================== -(void)preparePhotos{

    [self.assetsGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
    if(result == nil) {
    return;
    }
    [self.assetsArray addObject:result];
    }];
    [self allPhotosCollected:self.assetsArray];

    }
    //============================================================================ -(void)allPhotosCollected:(NSMutableArray*)imgArray
    {
    //write your code here after getting all the photos from library...
    NSLog(@"%@", imgArray);
    }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: