virtplay
virtplay

Reputation: 578

How to convert HEIC image to JPG image in IOS

Im having NSData of Image type HEIC (photo taken from IOS 12), I need to convert HEIC to JPG and then add to Photo library(to phone having IOS 10.3). Since IOS 10.3 doesn't support of HEIC photo type i need to convert and add to library. I have tried the following code but failed to add into library. for converting i used.

UIImageJPEGRepresentation([UIImage imageWithData:imageData], 0.7);

as suggested in other threads. But when i add the resulted data to Photo library i am getting error as Error Domain=NSCocoaErrorDomain Code=-1 "(null)".

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
                        [[PHAssetCreationRequest creationRequestForAsset] addResourceWithType:PHAssetResourceTypePhoto data:imageData options:nil];
                    } completionHandler:^(BOOL success, NSError * _Nullable error) {
                        if (error) {
                            [weakSelf writeLog:[NSString stringWithFormat:@"Error on adding photo to photo album: %@",error.debugDescription]];
                        }
                        dispatch_semaphore_signal(weakSelf.savephoto);
                    }];

Upvotes: 2

Views: 729

Answers (0)

Related Questions