如何将 gif 保存到我的相册?

use*_*312 4 iphone objective-c ios

我尝试使用 UIImageWriteToSavedPhotosAlbum 和 ALAssetsLibrary 将我的 gif 保存到相册。但是当我尝试通过电子邮件发送 gif 时,它没有动画。我很确定元数据在保存时会丢失。有谁知道如何保存 gif 元数据?

谢谢

Har*_*ain 5

一个很老的问题,但它可能对某人有所帮助!

我使用此代码将 GIF 保存在相册中,它工作正常,通过在 MailViewComposer 和 iMessage 中打开 GIF 进行测试。

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

NSData *data = [NSData dataWithContentsOfFile:tempPath]; // Your GIF file path which you might have saved in NSDocumentDir or NSTempDir

[library writeImageDataToSavedPhotosAlbum:data metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
    if (error) {
        NSLog(@"Error Saving GIF to Photo Album: %@", error);
    } else {
        // TODO: success handling
        NSLog(@"GIF Saved to %@", assetURL);

        success(tempPath);
    }
}];
Run Code Online (Sandbox Code Playgroud)