星五博客

获取手机照片及属性

liberary = [[ALAssetsLibraryalloc] init];
// 使用参数 ALAssetsGroupSavedPhotos 取出所有保存照片
[liberaryenumerateGroupsWithTypes:
  ALAssetsGroupSavedPhotosusingBlock:^(ALAssetsGroup *group, BOOL *stop){
    //NSLog(@"Gropu:%@", group);
    NSMutableArray *tempArray =[[NSMutableArrayalloc] init];
    if (group != nil) {
      [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
        if(result != nil){
          [tempArray addObject:result];
          // NSLog(@"%@",result);
          NSDateFormatter *dateFormatter = [[NSDateFormatteralloc] init];
          [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
          NSString *currentDate =
            [dateFormatter stringFromDate:[result valueForProperty: ALAssetPropertyDate]];
          NSLog(@"\n日期%@\n文件%@",currentDate,[result valueForProperty: ALAssetPropertyAssetURL]);
        }
      }];
      // 保存结果
      imageArray = [tempArray copy];
      NSLog(@"取出照片共 %lu 张", [imageArraycount]);
    }
  } failureBlock:^(NSError *error) {
  //读取照片失败
}];


IOS