iOS中的ALAsset库
它的代码在模拟器上工作,但在设备上不工作,我不能从设备上获取画廊图像iOS中的ALAsset库,ios,objective-c,iphone,alassetslibrary,alasset,Ios,Objective C,Iphone,Alassetslibrary,Alasset,它的代码在模拟器上工作,但在设备上不工作,我不能从设备上获取画廊图像 imageArray=[[NSArray alloc] init]; name=[[NSArray alloc]init]; mutableArray =[[NSMutableArray alloc]init]; // self.title = [library valueForProperty:ALAssetsGroupPropertyName]; ALAuthorizationStatus status = [ALAs
imageArray=[[NSArray alloc] init];
name=[[NSArray alloc]init];
mutableArray =[[NSMutableArray alloc]init];
// self.title = [library valueForProperty:ALAssetsGroupPropertyName];
ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
NSMutableArray* assetURLDictionaries = [[NSMutableArray alloc] init];
library = [[ALAssetsLibrary alloc] init];
void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
NSLog(@"%zd",result);
if(result != nil) {
if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {
[assetURLDictionaries addObject:[result valueForProperty:ALAssetPropertyURLs]];
NSURL *url= (NSURL*) [[result defaultRepresentation]url];
[library assetForURL:url
resultBlock:^(ALAsset *asset) {
[mutableArray addObject:[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]]];
if ([mutableArray count]==count ) {
// name=[[NSArray alloc]initWithArray:lisk];
imageArray=[[NSArray alloc] initWithArray:mutableArray];
_listImageArrayFromGallery=[[NSMutableArray alloc]init];
for (int i=0; i<imageArray.count; i++) {
[_listImageArrayFromGallery addObject:[imageArray objectAtIndex:i]];
}
NSLog(@"ListPic%@",_listImageArrayFromGallery);
loadedCards = [[NSMutableArray alloc] init];
allCards = [[NSMutableArray alloc] init];
cardsLoadedIndex = 0;
[self loadCards];
// [self allPhotosCollected:imageArray];
}
}
failureBlock:^(NSError *error){ NSLog(@"operation was not successfull!"); } ];
}
}
};
NSMutableArray *assetGroups = [[NSMutableArray alloc] init];
void (^ assetGroupEnumerator) ( ALAssetsGroup *, BOOL *)= ^(ALAssetsGroup *group, BOOL *stop) {
if(group != nil) {
[group enumerateAssetsUsingBlock:assetEnumerator];
[assetGroups addObject:group];
count=[group numberOfAssets];
//[assetGrpImage addObject:assetGroups];
//assetGrpImage=[assetGrpImage valueForKey:@"Camera Roll"];
}
};
assetGroups = [[NSMutableArray alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
failureBlock:^(NSError *error) {NSLog(@"There is an error");}];
imageArray=[[NSArray alloc]init];
name=[[NSArray alloc]init];
mutableArray=[[NSMutableArray alloc]init];
//self.title=[library valueForProperty:ALAssetsGroupPropertyName];
AlaAuthorizationStatus=[ALAssetsLibrary authorizationStatus];
NSMutableArray*assetURLDictionaries=[[NSMutableArray alloc]init];
库=[[AlassetLibrary alloc]init];
void(^assetEnumerator)(ALAsset*,NSUTEGER,BOOL*)=^(ALAsset*结果,NSUTEGER索引,BOOL*停止){
NSLog(@“%zd”,结果);
如果(结果!=零){
if([[result valueForProperty:ALAssetPropertyType]IseQualString:ALAssetTypePhoto]){
[AssetUrdictionares addObject:[result valueForProperty:ALAssetPropertyURLs]];
NSURL*url=(NSURL*)[[result defaultRepresentation]url];
[library assetForURL:url
结果块:^(ALAsset*资产){
[mutableArray addObject:[UIImage imageWithCGImage:[[asset defaultRepresentation]fullScreenImage]];
if([mutableArray count]==计数){
//name=[[NSArray alloc]initWithArray:lisk];
imageArray=[[NSArray alloc]initWithArray:mutableArray];
_listImageArrayFromGallery=[[NSMutableArray alloc]init];
对于(int i=0;i选中此答案,因为SetLibrary在iOS 9上不受欢迎,我认为它甚至不能在iOS 9上正常工作。此代码应该在iOS 7或8上工作。但是在iOS 9中,您必须使用PHPhotoLibrary.go-