gpt4 book ai didi

ios - 不使用 ImagePickerController 获取图像

转载 作者:行者123 更新时间:2023-11-29 01:03:28 26 4
gpt4 key购买 nike

我一直在尝试通过 PHAsset 在不使用 UIImagePickerController 的情况下获取图库照片。当我从 PHAsset 获取图像时,它会占用大量内存。有没有其他方法可以在不使用 PHAsset 库的情况下获取照片

最佳答案

试试这个。

- (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];
}
}];
}

获取权限

+ (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;
}
}

关于ios - 不使用 ImagePickerController 获取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36717641/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com