0

The app takes pictures. Then is meant to save those pictures using the below code in the delegate method:

public func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
        
    // Abort if an error was faced.
    guard error.isNone else {
        print("Error capturing photo: \(error!).")
        return
    }

    // Get the image data from the photo.
    guard let imageData=photo.fileDataRepresentation() else {
        print("Error converting photo to data.")
        return
    }

    // Create a `UIImage` from the image data.
    guard let image: UIImage = .init(data: imageData) else {
        print("Error converting data to a `UIImage`.")
        return
    }
    
    // Edit image.
    let result: UIImage=UIGraphicsImageRenderer(size: image.size).image(actions: { _ in
        ...
    })
    
    // Save edited image to photo library.
    PHPhotoLibrary.shared().performChanges {
        let creationRequest: PHAssetChangeRequest = .creationRequestForAsset(from: result)

        // Add metadata to the photo.
        creationRequest.creationDate = Date()
        if let location=self.location {
            creationRequest.location = .init(latitude: location.latitude, longitude: location.longitude)
        }
    }
}

However, I need to save some metadata with the photo. The metadata is two strings. One is a description and the other is a category. How can I include these strings in the saved photo's metadata?

shoe
  • 952
  • 1
  • 20
  • 44

0 Answers0