iOS - 从图库中自动导入新图像

时间:2014-08-22 22:04:25

标签: ios uiimagepickercontroller

有很多例子可以使用UIImagePicker从图库中导入一个或多个图像,但是我想自动检测新图像(就像dropbox一样)并在我的应用程序中导入新图像。有没有办法在不打开imagepicker的情况下检测新图像?如果没有可能性?感谢。

1 个答案:

答案 0 :(得分:0)

您可以使用ALAssetLibrary轻松获取所有图像信息而不使用UIImagePicker它将为您提供所有图像和视频信息,您可以将其存储在本地的coredata中,如果有来自ALAssetLibrary的图像/视频信息,则可以进行常规检查这不是你的coredata hanse它是一个新的图像/视频。

来自我的个人应用程序的ALAssetLibrary示例代码,它可以运行prefectoly

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop)
 {
     [group enumerateAssetsUsingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop)
      {
          if (alAsset)
          {
              ALAssetRepresentation *representation =[alAsset defaultRepresentation];
              NSURL *url = [representation url];
              NSString *assetType=[alAsset valueForProperty:ALAssetPropertyType];

              // You can store this info in coreData
          }
      }];
 } failureBlock: ^(NSError *error)
 {
     UIAlertView *alrt = [[UIAlertView alloc] initWithTitle:@"Permission Denied" message:@"Apple restrictions prevent our app from accessing your Library without your permission. In order to access your media you must enable privacy setting " delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
     [alrt show];
 }
 ];