iOS中区分照片的来源
原理就是通过枚举出每个assets group,然后取得group property,group property是个整数,对应头文件中的一些枚举值。用这个可以判断照片是从哪来的(相机胶卷、照片流、相册),进一步的可以结合persistent id来判断照片的来源是从设备上创建还是来自于我的电脑
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
NSLog(@"%@", group);
[group setAssetsFilter:[ALAssetsFilter allAssets]];
NSLog(@"名称:%@", [group valueForProperty:ALAssetsGroupPropertyName]);
NSNumber* groupType = [group valueForProperty:ALAssetsGroupPropertyType];
switch ([groupType unsignedIntegerValue]) {
case ALAssetsGroupAlbum:
{
NSLog(@"来自我的电脑或者是在设备上创建");
NSString* persistentID = [group valueForProperty:ALAssetsGroupPropertyPersistentID];
if ([[persistentID substringWithRange:NSRangeFromString(@"0,8")] isEqualToString:@"00000000"])
{
NSLog(@"来自我的电脑");
}
break;
}
case ALAssetsGroupSavedPhotos:
NSLog(@"相机胶卷");
break;
case ALAssetsGroupPhotoStream:
NSLog(@"我的照片流");
break;
default:
break;
}
}
failureBlock: ^(NSError *error)
{
NSLog(@"No groups");
}];