仅使用ALAssetLibray获取iPhone相机拍摄的照片

时间:2014-05-15 07:47:38

标签: ios objective-c alassetslibrary alasset

我正在使用ALAssetLibrary来访问相机胶卷。但它正在获取所有图像,例如应用程序图像,Facebook图像等。

我的代码是这样的:

[_library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
    if (group) {
        [group setAssetsFilter:[ALAssetsFilter allPhotos]];
        [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) {
            if (asset) {
               //Getting photos here 
        }];
    }     } failureBlock:^(NSError *error) {
    NSLog(@"Failed.");
}];

有没有办法只使用ALAssetLibrary获取相机拍摄照片?

1 个答案:

答案 0 :(得分:3)

相机拍摄的照片和WhatsApp图像之间的唯一区别是EXIF数据。

你可以用

读出来
ALAssetRepresentation *representation = [asset defaultRepresentation];
NSDictionary *meta = [representation metadata];

或在Swift中:

var representation = asset.defaultRepresentation()
var meta = representation.metadata()

返回以下内容:

{TIFF}: {
    DateTime = "2014:04:01 20:33:59";
    Make = Apple;
    Model = "iPhone 5";
    Orientation = 3;
    ResolutionUnit = 2;
    Software = "7.1";
    XResolution = 72;
    YResolution = 72;
}, PixelWidth: 3264]

因此,您可以检查Make是Apple,对于WhatsApp图像,它是空的:

if([metaData["{TIFF}"]["Make"] isEqualToString: @"Apple"])

或在Swift中:

if metaData["{TIFF}"]!["Make"] == "Apple"