0

I downloaded an gif image from the network using AFNetworking 2.0 then save it to camera roll using ALAssetsLibrary

[assetsLibrary writeImageToSavedPhotosAlbum:[responseObject CGImage] orientation:(ALAssetOrientation)[responseObject imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error)
{
    if (error)
    {
        [App showAlertWithTitle:@"Error" message:@"Save message failed"];
    }
    else
    {
        [App showAlertWithTitle:@"Success" message:@"Saved success"];
    }
}];

Then I tried to retrieve this image from camera using UIImagePickerViewController, but the image I retrieved was not a GIF image but a jpeg image with reference url:

UIImagePickerControllerReferenceURL = "assets-library://asset/asset.JPG?id=2E7C87E4-5853-4946-B86B-CC8AAF094307&ext=JPG";

I don't know whether the fault is ALAssetsLibrary or UIImagePickerViewController and how to surpass it

Doan Cuong
  • 2,594
  • 4
  • 22
  • 39

2 Answers2

0

The photo library does not support GIFs.

It has support for PHAssetMediaTypeImage (a JPG), PHAssetMediaTypeVideo (a MOV), or PHAssetMediaTypeAudio (probably an M4A, not sure here).

https://developer.apple.com/library/ios/documentation/Photos/Reference/Photos_Constants/index.html#//apple_ref/c/tdef/PHAssetMediaSubtype

StilesCrisis
  • 15,972
  • 4
  • 39
  • 62
  • 1
    That the Photos framework has somewhat limited format-saving support doesn't mean that the Library has. However, a `PHAssetMediaTypeImage` isn't restricted to JPEG, which is how saved PNGs, TIFFs and, yes, GIFs can appear in your Photos app. In fact, the docs to which you refer only say "The asset is a photo or other static image", with no reference to JPEG at all. – Wildaker Oct 29 '14 at 10:54
-1

The writeImageToSavedPhotosAlbum: methods only save still images as JPEGs, as do the new Photos methods. However, there are ways of saving other formats, including (yes!) GIF.

You don't need to mess about with CGImageRefs—just grab the GIF data and then save it, using the writeImageDataToSavedPhotosAlbum:metadata:completionBlock: method. Something like this:

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
NSData *data = [NSData dataWithContentsOfURL:
    [NSURL URLWithString:@"http://somewhere/something.gif"]]];  
[library writeImageDataToSavedPhotosAlbum:data 
    metadata:nil 
    completionBlock:^(NSURL *assetURL, NSError *error) {
      if (error) {
        [App showAlertWithTitle:@"Error" message:@"Save message failed"];
      } else {
        [App showAlertWithTitle:@"Success" message:@"Saved success"];
      }
    }];

See this answer.

If you want to generate a GIF, it's somewhat more complex, but simply saving one is straightforward.

Community
  • 1
  • 1
Wildaker
  • 2,533
  • 1
  • 17
  • 19