[英]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.