ios 相册相关

时间:2021-11-16 06:22:19
1、ALAssetsLibrary 系统中的资源库,可以使用他来访问资源库中的资源,照片、视屏等。
    [ALAssetsLibrary authorizationStatus];获取当前应用能否访问相册资源
 
    [_library addAssetsGroupAlbumWIthName:@”” resultBlock:^(ALAssetsGroup *group) {
     //查看相册的名字
        NSLog(@"ALAssetsGroupPropertyName:%@",[group valueForProperty:ALAssetsGroupPropertyName]);
        //查看相册的类型
        NSLog(@"ALAssetsGroupPropertyType:%@",[group valueForProperty:ALAssetsGroupPropertyType]);
        //查看相册的存储id
        NSLog(@"ALAssetsGroupPropertyPersistentID:%@",[group valueForProperty:ALAssetsGroupPropertyPersistentID]);
        //查看相册存储的位置地址
        NSLog(@"ALAssetsGroupPropertyURL:%@",[group valueForProperty:ALAssetsGroupPropertyURL]);
        groupURL = [group valueForProperty:ALAssetsGroupPropertyURL];
 
}  failureBlock:^(NSError *error) {
}];     添加相册
 
 
[_library assetForRUL:[NSURL URLWithString:@“”] resultBlock:^(ALAsset *asset) {
            //查看资源的地理位置信息
 
        NSLog(@"ALAssetPropertyLocation:%@",[asset valueForProperty:ALAssetPropertyLocation]);
        //如果资源是视频,查看视频的时长
        NSLog(@"ALAssetPropertyDuration:%@",[asset valueForProperty:ALAssetPropertyDuration]);
        //查看资源的方向,图片的旋转方向
        NSLog(@"ALAssetPropertyOrientation:%@",[asset valueForProperty:ALAssetPropertyOrientation]);
        //查看资源的创建时间
        NSLog(@"ALAssetPropertyDate:%@",[asset valueForProperty:ALAssetPropertyDate]);
        //查看资源的描述信息
        NSLog(@"ALAssetPropertyRepresentations:%@",[asset valueForProperty:ALAssetPropertyRepresentations]);
        NSLog(@"ALAssetPropertyURLs:%@",[asset valueForProperty:ALAssetPropertyURLs]);
        //查看资源的url路径
        NSLog(@"ALAssetPropertyAssetURL:%@",[asset valueForProperty:ALAssetPropertyAssetURL]);
 
 
        //asset 拿到的图片都是CGImageRef的
} failureBlock:^(NSError *error) {
 
}]; 使用url读取图片
 
 
 
[_library groupForURL:groupURL resultBlock:^(ALAssetsGroup *group) {
 
}  failureBlock:^(NSError *error) {
 
}];  //通过url地址获取相册资源中的一个相册
 
[_library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group ,BOOL *stop) {
    
}  failureBlock:^(NSError *error) {
 
}];//迭代资源库中的资源group
enum {
     ALAssetsGroupLibrary        = (1 << 0),
     ALAssetsGroupAlbum          = (1 << 1),
     ALAssetsGroupEvent          = (1 << 2),
     ALAssetsGroupFaces          = (1 << 3),
     ALAssetsGroupSavedPhotos    = (1 << 4),
     ALAssetsGroupPhotoStream    = (1 << 5),
     ALAssetsGroupAll            = 0xFFFFFFFF,
     };
 
 
 
  //保存图片到系统默认的相册中,使用nsdata的形式,并返回照片的url地址
    [_library writeImageDataToSavedPhotosAlbum:nil metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
        
    }];
    //保存图片到系统默认的相册中,使用cgimageref的形式,并返回照片的url地址
    [_library writeImageToSavedPhotosAlbum:nil metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
        
    }];