0

After I pick one image by UIImagePickerController, I get UIImage and rewrite the image data to a temporary file. In the end, I use the temporary file location to upload this image to server. However, if I pick a gif, I will end up getting an image. I wonder if there is any way I can get gif by UIImagePickerController.

        UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
        NSData *jpegData = UIImageJPEGRepresentation(originalImage, 1);

        NSString *parentDirectoryPath = [NSString stringWithFormat:
                                                @"Pixured/%@Sessions/Session_%@",
                                                [CurrentAppUser getInstance].user.id,
                                                [PixuredUtility getTimeStamp]];

        if (![[NSFileManager defaultManager] fileExistsAtPath:[PixuredUtility appendDocumentsDirectory:parentDirectoryPath]]) {
            [[NSFileManager defaultManager] createDirectoryAtPath:[PixuredUtility appendDocumentsDirectory:parentDirectoryPath]
                                      withIntermediateDirectories:YES
                                                       attributes:nil
                                                            error:nil];
        }

        NSString *imageFilePath = [parentDirectoryPath stringByAppendingFormat:@"/RAW_IMG_%@.jpeg", [PixuredUtility generatePostID]];

        NSString *fullImageFilePath = [PixuredUtility appendDocumentsDirectory:imageFilePath];
        BOOL writeSuccess = [jpegData writeToFile:fullImageFilePath atomically:YES];

Thank you so much

Alex
  • 63
  • 1
  • 9
  • Your question should be how to load a gif from the photo library. Based on [this question](https://stackoverflow.com/questions/37934698/how-to-load-animated-gif-from-photo-library), you should use `PhotoKit` (the `Photos` framework) instead of `UIImagePickerController`, since that one only supports images and videos. BTW, an UIImage can't be a gif, so if you load a gif you'll need to keep it as data. – EmilioPelaez Jun 12 '18 at 18:03
  • It works using PHImageManager. However, UIImagePickerControllerPHAsset is only available after ios 11. Is any way to get PHAsset before ios 11? – Alex Jun 12 '18 at 19:09
  • Try `ALAssetsLibrary` – EmilioPelaez Jun 13 '18 at 00:39
  • Got it work. Thank you so much – Alex Jun 13 '18 at 19:01

0 Answers0