dispatch_async(dispatch_get_main_queue(), ^{
@autoreleasepool {
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *err){
if ([err.localizedDescription rangeOfString:@"Global denied access"].location!=NSNotFound) {
[SGMessage showMsg:@"无法访问相册.请在'设置->定位服务'设置为打开状态." confirmTitle:@"确定" delegate:nil];
}else{
[SGNotice showErr:@"相册访问失败"];
}
};
ALAssetsGroupEnumerationResultsBlock groupEnumerAtion = ^(ALAsset *result,NSUInteger index, BOOL *stop){
if (result!=NULL) {
if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {
// 完整的路径
NSString *urlstr=[NSString stringWithFormat:@"%@",result.defaultRepresentation.url];//图片的url
// 大图
// UIImage *image = [UIImage imageWithCGImage:result.defaultRepresentation.fullScreenImage];
// 缩略图
UIImage *thumbImage = [UIImage imageWithCGImage:result.thumbnail];
// 完整名称
// NSString *resultName= [[urlstr substringFromIndex:[urlstr rangeOfString:@"id="].location+3] stringByReplacingOccurrencesOfString:@"&ext=" withString:@"."];
[self.urlStringData addObject:urlstr];
}
}
};
ALAssetsLibraryGroupsEnumerationResultsBlock libraryGroupsEnumeration = ^(ALAssetsGroup* group,BOOL* stop){
if (group!=nil) {
// 取得分组名称
NSString *f = [NSString stringWithFormat:@"%@",group];//获取相簿的组
NSString *s = [f substringFromIndex:16 ];
NSArray *arr = [NSArray arrayWithArray:[s componentsSeparatedByString:@","]];
NSString *groupName = [[arr objectAtIndex:0]substringFromIndex:5];
NSLog(@"---%@", groupName);
if ([groupName isEqualToString:@"My Photo Stream"] ) {
[group enumerateAssetsUsingBlock:groupEnumerAtion];
}
}
};
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:libraryGroupsEnumeration
failureBlock:failureblock];
}
});
@autoreleasepool {
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *err){
if ([err.localizedDescription rangeOfString:@"Global denied access"].location!=NSNotFound) {
[SGMessage showMsg:@"无法访问相册.请在'设置->定位服务'设置为打开状态." confirmTitle:@"确定" delegate:nil];
}else{
[SGNotice showErr:@"相册访问失败"];
}
};
ALAssetsGroupEnumerationResultsBlock groupEnumerAtion = ^(ALAsset *result,NSUInteger index, BOOL *stop){
if (result!=NULL) {
if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {
// 完整的路径
NSString *urlstr=[NSString stringWithFormat:@"%@",result.defaultRepresentation.url];//图片的url
// 大图
// UIImage *image = [UIImage imageWithCGImage:result.defaultRepresentation.fullScreenImage];
// 缩略图
UIImage *thumbImage = [UIImage imageWithCGImage:result.thumbnail];
// 完整名称
// NSString *resultName= [[urlstr substringFromIndex:[urlstr rangeOfString:@"id="].location+3] stringByReplacingOccurrencesOfString:@"&ext=" withString:@"."];
[self.urlStringData addObject:urlstr];
}
}
};
ALAssetsLibraryGroupsEnumerationResultsBlock libraryGroupsEnumeration = ^(ALAssetsGroup* group,BOOL* stop){
if (group!=nil) {
// 取得分组名称
NSString *f = [NSString stringWithFormat:@"%@",group];//获取相簿的组
NSString *s = [f substringFromIndex:16 ];
NSArray *arr = [NSArray arrayWithArray:[s componentsSeparatedByString:@","]];
NSString *groupName = [[arr objectAtIndex:0]substringFromIndex:5];
NSLog(@"---%@", groupName);
if ([groupName isEqualToString:@"My Photo Stream"] ) {
[group enumerateAssetsUsingBlock:groupEnumerAtion];
}
}
};
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:libraryGroupsEnumeration
failureBlock:failureblock];
}
});