title: How to get the latest photo in iPhone Library?
body: <p>In my app there is a button, user just click it then the latest photo in library can be retrieved on screen directly. How to get the latest photo in library?</p>
  
  <hr>
  
  <p>2012/02/17</p>
  
  <p>this can get ALAsset</p>
  
  <pre><code>void (^assetEnumerator)(ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop)
      {
          if(result != nil)
          {
  
              [self.assets addObject:result];
  
          }
      };
  
      void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
      {
          if(group != nil)
          {
              [group setAssetsFilter:[ALAssetsFilter allPhotos]];
              [group enumerateAssetsUsingBlock:assetEnumerator];
          }else{
              self.image = [self getLastImage];
  
          }
  
      };
      ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror){
          NSLog(@"error occour =%@", [myerror localizedDescription]);
      };
  
  
      assets = [[NSMutableArray alloc] init];
      ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init];
      [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:assetGroupEnumerator failureBlock:failureblock];
      [assetsLibrary release];
  </code></pre>
  
  <p>To get file date I use this</p>
  
  <pre><code>    assetURLArray = [[NSMutableArray alloc] init];
      for (ALAsset *asset in self.assets) {
          NSDate * date = [asset valueForProperty:ALAssetPropertyDate];
  </code></pre>
  
  <p>Then I found that the latest image always be the top one of assetURLArray, so I finally get the latest one like this</p>
  
  <pre><code>if (self.assets &amp;&amp; [self.assets count]) {
          ALAsset *asset = [self.assets objectAtIndex:([self.assets count] - 1)];
          CGImageRef ref = [[asset defaultRepresentation]fullResolutionImage];
  </code></pre>
  
  <p>I donno if this is always work... hope any one can prove me.</p>
  
  <p>And there I'm looking for a way to sync thread... </p>