我正试图通过ALAssetsLibrary访问iPhone的相册照片图片。我可以访问所有相册并通过以下代码获取模拟器上每个图像的资产URL:
- (void)viewDidLoad
{
[super viewDidLoad];
void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
if(result != NULL) {
NSLog(@"See Asset: %@", result);
// assets is a NSMutableArray..
[assets addObject:result];
// Here storing the asset's image URL's in NSMutablearray urlStoreArr
NSURL *url = [[result defaultRepresentation] url];
[urlStoreArr addObject:url];
}
};
void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
{
if(group != nil) {
[group enumerateAssetsUsingBlock:assetEnumerator];
}
[self.activity stopAnimating];
[self.activity setHidden:YES];
};
assets = [[NSMutableArray alloc] init];
library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAlbum usingBlock:assetGroupEnumerator failureBlock: ^(NSError *error) {
NSLog(@"Failure");
}];
urlStoreArr = [[NSMutableArray alloc] init];
}
-(void) GetURLImages
{
for (int i=0; i<[urlStoreArr count]; i++)
{
// To get the each image URL here...
NSString *str = [urlStoreArr objectAtIndex:i];
NSLog(@"str: %@",str);
}
}
它在iOS 4.0模拟器上按预期工作,即获取所有图像URL(例如:assets-library://asset/asset.JPG?id=1000000002&ext=JPG
)。但它不能在iPod 4.1设备上检索图像URL。这可能是什么问题?有人可以帮我修复,这样代码也可以在iPod上运行吗?我完全糊涂了。
谢谢!
答案 0 :(得分:1)
尝试我在评论或以下内容中提到的内容
library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
这也取决于你想要的照片。
答案 1 :(得分:0)
void(^ assetGroupEnumerator)(struct ALAssetsGroup *,BOOL *)= ^(ALAssetsGroup * group,BOOL * stop) {
if(group != nil) {
[group enumerateAssetsUsingBlock:assetEnumerator];
}
[self.activity stopAnimating];
[self.activity setHidden:YES];
/ * make * / group = nil; //否则枚举三次。 };