我使用此代碼檢索所有的圖像形成我的設備,但它不是返回一個結果需要幫助有關資產庫
- (void)viewDidLoad
{
[super viewDidLoad];
void (^assetEnumerator)(ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
if(result != NULL) {
NSLog(@"See Asset: %@", result);
[_assets addObject:result];
// Here storing the asset's image URL's in NSMutable array urlStoreArr
NSURL *url = [[result defaultRepresentation] url];
[_urlStoreArr addObject:url];
}
};
void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
{
if(group != nil)
{
[group enumerateAssetsUsingBlock:assetEnumerator];
}
};
_urlStoreArr = [[NSMutableArray alloc] init];
_assets = [[NSMutableArray alloc] init];
_library = [[ALAssetsLibrary alloc] init];
[_library enumerateGroupsWithTypes:ALAssetsGroupAlbum
usingBlock:assetGroupEnumerator
failureBlock: ^(NSError *error) {
NSLog(@"Failure");
}];
[self UploadImagesToServer];
}
-(void) UploadImagesToServer
{
for (int i=0; i<[_urlStoreArr count]; i++)
{
// To get the each image URL here...
NSString *str = [_urlStoreArr objectAtIndex:i];
NSLog(@"str: %@",str);
// Need to upload the images to my server..
}
}
這是一個很好的使用Assets庫的教程,可能對您有所幫助。 http://www.icodeblog.com/2010/07/08/asset-libraries-and-blocks-in-ios-4/ –