简体   繁体   中英

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. 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 example code from my personal app and it works 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];
 }
 ];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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