简体   繁体   English

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

[英]iOS - Auto-Import new images from image gallery

There are many examples to import one or many images from gallery using UIImagePicker, however I want to detect new images automatically (just like dropbox) and import new images inside my app. 有很多示例可以使用UIImagePicker从图库中导入一个或多个图像,但是我想自动检测新图像(就像Dropbox一样)并在我的应用程序中导入新图像。 Is there any way I can detect new images without opening imagepicker? 有什么方法可以在不打开图像选择器的情况下检测新图像? if not what are the possibilities? 如果不是,那有什么可能性? Thank. 谢谢。

You can easily get all images information without UIImagePicker by using ALAssetLibrary it will gives you all images and video information, you can store it locally in coredata and perodically check it if there is an image/video info from ALAssetLibrary which is not in you coredata hanse it's a new image/video. 您可以通过使用ALAssetLibrary轻松获得所有图像信息,而无需使用UIImagePicker,它将为您提供所有图像和视频信息,您可以将其本地存储在coredata中,并定期检查是否有ALAssetLibrary中的图像/视频信息不在您的coredata中。这是新的图像/视频。

ALAssetLibrary example code from my personal app and it works prefectoly 我的个人应用程序中的ALAssetLibrary示例代码,可完美运行

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM