2014-01-09 2 views
0

사진 라이브러리의 이미지를 타임 스탬프 (작성 또는 수정 된 시간)와 함께 표시하려고합니다. 다음 코드를 사용하여 이미지를 가져 왔습니다. 타임 스탬프를 올바르게 가져올 수 있습니까? 여기에 코드입니다 :ALAssetLibrary를 사용하여 Photo Library에서 이미지의 타임 스탬프를 가져옵니다.

-(void)getAllPictures{ 
imageArray=[[NSArray alloc] init]; 
mutableArray =[[NSMutableArray alloc]init]; 
NSMutableArray* assetURLDictionaries = [[NSMutableArray alloc] init]; 

library = [[ALAssetsLibrary alloc] init]; 

void (^assetEnumerator)(ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) { 
    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) 
         { 
          imageArray=[[NSArray alloc] initWithArray:mutableArray]; 
          [self allPhotosCollected:imageArray]; 
         } 
        } 
        failureBlock:^(NSError *error){ NSLog(@"operation was not successfull!"); } ]; 
      NSLog(@"ali: %@",result); 

     } 
    } 
}; 

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

assetGroups = [[NSMutableArray alloc] init]; 

[library enumerateGroupsWithTypes:ALAssetsGroupAll 
         usingBlock:assetGroupEnumerator 
        failureBlock:^(NSError *error) {NSLog(@"There is an error");}];} 
-(void)allPhotosCollected:(NSArray*)imgArray{ 
//write your code here after getting all the photos from library... 
NSLog(@"all pictures are %@",imgArray); 
for (int i=0; i<imgArray.count; i++) { 


UIImageView *img=[[UIImageView alloc] initWithImage:imgArray[i]]; 
img.frame=CGRectMake(10, 20+105*i, 200, 100); 
[self.view addSubview:img]; 

} 

은}

답변

1

타임 스탬프 사용이 효율적으로 활용하려면 다음

NSDate *date = [asset valueForProperty:ALAssetPropertyDate]; 
관련 문제