I have been trying to get gallery photos without using UIImagePickerController though PHAsset ..When I get images from PHAsset its takes a lot of memory ..Is there any other way to get photos without using PHAsset Library
Asked
Active
Viewed 59 times
1 Answers
1
Try this.
- (ALAssetsLibrary *)defaultAssetsLibrary
{
static dispatch_once_t pred = 0;
static ALAssetsLibrary *library = nil;
dispatch_once(&pred, ^{
library = [[ALAssetsLibrary alloc] init];
});
return library;
}
- (void)loadThumbnails
{
photosArray = [[NSMutableArray alloc] init];
ALAssetsLibrary *assetLibrary = [self defaultAssetsLibrary];
[assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (group)
{
if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:@"Camera Roll"])
[self getContentFrom:group withAssetFilter:[ALAssetsFilter allPhotos]];
}
} failureBlock:^(NSError *error) {
NSLog(@"Error Description %@",[error description]);
}];
}
- (void) getContentFrom:(ALAssetsGroup *) group withAssetFilter:(ALAssetsFilter *)filter
{
[group setAssetsFilter:filter];
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (result) {
NSMutableDictionary *tempDictionary = [[NSMutableDictionary alloc] init];
[tempDictionary setObject:result forKey:@"thumbnail"];
[tempDictionary setObject:@"0" forKey:@"selected"];
[photosArray addObject:tempDictionary];
} else {
//Finish load Assets
photosArray = [[[photosArray reverseObjectEnumerator] allObjects] mutableCopy];
[collectionViewMedia reloadData];
}
}];
}
For Get permissions
+ (void)requestPermissions:(GalleryPermission)callback
{
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
switch (status)
{
case PHAuthorizationStatusAuthorized:
callback(YES);
break;
case PHAuthorizationStatusNotDetermined:
{
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus authorizationStatus)
{
if (authorizationStatus == PHAuthorizationStatusAuthorized)
callback(YES);
else
callback(NO);
}];
break;
}
default:
callback(NO);
break;
}
}

jose920405
- 7,982
- 6
- 45
- 71
-
ALAsset is deprecated ..will it be feasible? – jeremy gv Apr 19 '16 at 12:53
-
Yes, but only for get permissions to photos gallery. The way for get permissions in the answer. (updated) – jose920405 Apr 19 '16 at 12:56