[英]iOS - Auto-Import new images from image gallery
有很多示例可以使用UIImagePicker从图库中导入一个或多个图像,但是我想自动检测新图像(就像Dropbox一样)并在我的应用程序中导入新图像。 有什么方法可以在不打开图像选择器的情况下检测新图像? 如果不是,那有什么可能性? 谢谢。
您可以通过使用ALAssetLibrary轻松获得所有图像信息,而无需使用UIImagePicker,它将为您提供所有图像和视频信息,您可以将其本地存储在coredata中,并定期检查是否有ALAssetLibrary中的图像/视频信息不在您的coredata中。这是新的图像/视频。
我的个人应用程序中的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.