iPhone ALAssetsLibrary 获取所有图像并进行编辑

发布于 2024-12-06 18:33:54 字数 98 浏览 3 评论 0原文

请帮助我解决我的问题:

我可以使用 ALAssetsLibrary 提供 iPhone 库中所有图像/视频的 URL 和元数据吗? 我可以编辑/删除这些图片/视频吗?

please help me with my question:

Can I give URLs and metadata for all the images/videos in iPhone library with ALAssetsLibrary?
Can I edit/delete these images/videos?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嗳卜坏 2024-12-13 18:33:54

上面的代码缺少一些大括号,因此在下面解决

ALAssetsLibrary *al = [[ALAssetsLibrary alloc] init];
assets = [[NSMutableArray alloc] init];
[al enumerateGroupsWithTypes:ALAssetsGroupAll

                  usingBlock:^(ALAssetsGroup *group, BOOL *stop)
 {
     [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
      {
          if (asset)
          {  
               NSLog(@"%@",asset);  

              NSLog(@".. do something with the asset");    
          }
      }
      ];
 }

                         failureBlock:^(NSError *error)
      {
          // User did not allow access to library
         // .. handle error 
      }
      ] ;

the above code has missed some braces so it is resolved below

ALAssetsLibrary *al = [[ALAssetsLibrary alloc] init];
assets = [[NSMutableArray alloc] init];
[al enumerateGroupsWithTypes:ALAssetsGroupAll

                  usingBlock:^(ALAssetsGroup *group, BOOL *stop)
 {
     [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
      {
          if (asset)
          {  
               NSLog(@"%@",asset);  

              NSLog(@".. do something with the asset");    
          }
      }
      ];
 }

                         failureBlock:^(NSError *error)
      {
          // User did not allow access to library
         // .. handle error 
      }
      ] ;
凡尘雨 2024-12-13 18:33:54

查看 ALAssetsLibrary 的文档 这里。要访问所有照片和视频,您需要枚举照片库中的所有组(相册),然后枚举每个组中的所有照片和图像。您无法使用 API 删除资产。 iOS 5 添加了额外的功能 - 但仍处于 NDA 状态,无法在此讨论 - 请查看 iOS5 的测试版文档和 Apple 开发者论坛。

您的代码需要执行以下操作:

ALAssetsLibrary *al = [[ALAssetsLibrary alloc] init];


[al enumerateGroupsWithTypes:ALAssetsGroupAll

    usingBlock:^(ALAssetsGroup *group, BOOL *stop)
    {
        [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
        {
            if (asset)
            {                
                 .. do something with the asset
            }
        }
        ];
    }

    failureBlock:^(NSError *error)
    {
        // User did not allow access to library
        .. handle error 
    }
 ];

Take a look at the documentation for ALAssetsLibrary here. To access all photos and videos you need to enumerate all groups (albums) in the photo library and then enumerate all photos and images in each group. You cannot delete assets using the API. iOS 5 adds extra functionality - it's still under NDA though and cannot be discussed here - have a look at the beta documentation and Apple Developer forums for iOS5.

Your code will need to do something like this:

ALAssetsLibrary *al = [[ALAssetsLibrary alloc] init];


[al enumerateGroupsWithTypes:ALAssetsGroupAll

    usingBlock:^(ALAssetsGroup *group, BOOL *stop)
    {
        [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
        {
            if (asset)
            {                
                 .. do something with the asset
            }
        }
        ];
    }

    failureBlock:^(NSError *error)
    {
        // User did not allow access to library
        .. handle error 
    }
 ];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文