在 iOS 8 上使用照片框架查找(照片库)iOS 设备中照片和视频的大小
Find the size of photos and videos inside (Photo Library) iOS device using Photos Framework on iOS 8
直到 iOS 7 我们一直在使用 Assets Library Framework 来获取 iOS 设备中照片和视频的总大小,请看这里:
How to find total size for images and videos inside photo library in iOS
任何人都可以帮助我使用 Photos Framework 做同样的事情,因为 Assets Library Framework 已被弃用。另外,如果有大量照片以更快的方式计算总大小,我该如何计算。
你可以在这个应用程序中看到:
MobiShield for iPhone 在这里,如果您转到更多 > 磁盘,您可以看到开发人员正在计算 2 秒内照片和视频的总大小。我怎样才能做到这一点?在 Objective - C.
User Photo Assets(我还没有使用过,但这是 IOS 8 要求)或已弃用但仍在使用当前版本的 ALASSETS,这将为您提供文件信息。
使用这些:
- (NSUInteger)updateVideoCount
{
ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
if (status==ALAuthorizationStatusDenied) {
[self goToSettingsAlert];
}
videoCount = 0;
totalVideoSize = 0;
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
[assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
[group setAssetsFilter:[ALAssetsFilter allVideos]];
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) {
if (asset)
{
NSString *type = [asset valueForProperty:ALAssetPropertyType];
if ([type isEqualToString:ALAssetTypeVideo])
{
videoCount++;
ALAssetRepresentation *rep = [asset defaultRepresentation];
totalVideoSize += rep.size;
}
}
else
{
}
}];
if(group==nil)
{
[self loadTable];
descTable.hidden = NO;
[descTable reloadData];
}
} failureBlock:^(NSError *error) {
}];
return 0;
}
- (NSUInteger)updatePictureCount
{
photoCount = 0;
totalPictureSize = 0;
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
[assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) {
if (asset)
{
NSString *type = [asset valueForProperty:ALAssetPropertyType];
if ([type isEqualToString:ALAssetTypePhoto])
{
photoCount++;
ALAssetRepresentation *rep = [asset defaultRepresentation];
totalPictureSize += rep.size;
}
}
else
{
}
}];
if(group==nil)
{
[self loadTable];
descTable.hidden = NO;
[descTable reloadData];
}
} failureBlock:^(NSError *error) {
}];
return 0;
}
直到 iOS 7 我们一直在使用 Assets Library Framework 来获取 iOS 设备中照片和视频的总大小,请看这里: How to find total size for images and videos inside photo library in iOS
任何人都可以帮助我使用 Photos Framework 做同样的事情,因为 Assets Library Framework 已被弃用。另外,如果有大量照片以更快的方式计算总大小,我该如何计算。 你可以在这个应用程序中看到: MobiShield for iPhone 在这里,如果您转到更多 > 磁盘,您可以看到开发人员正在计算 2 秒内照片和视频的总大小。我怎样才能做到这一点?在 Objective - C.
User Photo Assets(我还没有使用过,但这是 IOS 8 要求)或已弃用但仍在使用当前版本的 ALASSETS,这将为您提供文件信息。
使用这些:
- (NSUInteger)updateVideoCount
{
ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
if (status==ALAuthorizationStatusDenied) {
[self goToSettingsAlert];
}
videoCount = 0;
totalVideoSize = 0;
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
[assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
[group setAssetsFilter:[ALAssetsFilter allVideos]];
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) {
if (asset)
{
NSString *type = [asset valueForProperty:ALAssetPropertyType];
if ([type isEqualToString:ALAssetTypeVideo])
{
videoCount++;
ALAssetRepresentation *rep = [asset defaultRepresentation];
totalVideoSize += rep.size;
}
}
else
{
}
}];
if(group==nil)
{
[self loadTable];
descTable.hidden = NO;
[descTable reloadData];
}
} failureBlock:^(NSError *error) {
}];
return 0;
}
- (NSUInteger)updatePictureCount
{
photoCount = 0;
totalPictureSize = 0;
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
[assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) {
if (asset)
{
NSString *type = [asset valueForProperty:ALAssetPropertyType];
if ([type isEqualToString:ALAssetTypePhoto])
{
photoCount++;
ALAssetRepresentation *rep = [asset defaultRepresentation];
totalPictureSize += rep.size;
}
}
else
{
}
}];
if(group==nil)
{
[self loadTable];
descTable.hidden = NO;
[descTable reloadData];
}
} failureBlock:^(NSError *error) {
}];
return 0;
}