17.9 C
London
Friday, September 6, 2024

ios – Exif in React native utilizing swift


I’m attempting to write down exif in native manner in react native in ios this fuction is named from react native and additionally it is referred to as and return me the file saved url too. I’ve checked all of the print assertion i can see the exif print(“exif metadata”, metadata) written on this line however once I verify from react native I cant see any exif written however checking exif in android picture is working. Are you able to please assist by seeing this code wheather it’s right or not

func writeExifData(_ filePath: String, remark: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
    guard let imageURL = URL(string: filePath) else {
        reject("Error Invalid_File_Path", "Invalid file path offered", nil)
        return
    }
 
    print("exif imageURL", imageURL)
 
    guard let imageSource = CGImageSourceCreateWithURL(imageURL as CFURL, nil) else {
        reject("Error Image_Source_Failure", "Didn't create picture supply", nil)
        return
    }
    print("exif imageSource", imageSource)
 
    guard let imageDestination = CGImageDestinationCreateWithURL(imageURL as CFURL, kUTTypeJPEG, 1, nil) else {
        reject("Error Image_Destination_Failure", "Didn't create picture vacation spot", nil)
        return
    }
    print("exif imageDestination", imageDestination)
 
    guard let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as? [CFString: Any] else {
        reject("Error Image_Properties_Failure", "Didn't retrieve picture properties", nil)
        return
    }
 
    print("exif imageProperties", imageProperties)
 
    var metadata = imageProperties[kCGImagePropertyExifDictionary] as? [CFString: Any] ?? [CFString: Any]()
    metadata[kCGImagePropertyExifUserComment] = remark
 
    print("exif metadata", metadata)
  ``print("exif metaData userComment", metadata[kCGImagePropertyExifUserComment] ?? "no metadata")
 
    guard let picture = CGImageSourceCreateImageAtIndex(imageSource, 0, nil) else {
        reject("Error Image_Creation_Failure", "Didn't create picture", nil)
        return
    }
 
    print("exif metadata", picture)
    CGImageDestinationAddImage(imageDestination, picture, metadata as CFDictionary)
 
    if CGImageDestinationFinalize(imageDestination) {
        // Retrieve absolutely the string illustration of the imageURL
        let fileLocation = imageURL.path
        print(fileLocation, "Exif location")
        resolve(fileLocation)
    } else {
        reject("Error: Image_Save_Failure", "Failed to save lots of picture with up to date EXIF knowledge", nil)
    }
}

I’m anticipating to write down exif and add to s3 in react native I’ve written native modules for android and in addition tried in ios however not working in ios. Thanks in Advance

For Sort Notes: I dont know swift or goal C

Latest news
Related news

LEAVE A REPLY

Please enter your comment!
Please enter your name here