save image to gallery swiftui

it want to save QRCode to galley and i get the image but why it not save??

func saveImageQRCode(from string: String) {
    filter.message = Data(string.utf8)

    if let outputImage = filter.outputImage {
      if context.createCGImage(outputImage, from: outputImage.extent) != nil {
//        let ge = UIImage(cgImage: cgimg)
        let transform = CGAffineTransform(scaleX: 10, y: 10)
        let scaledCIImage = outputImage.transformed(by: transform)
        let uiimage = UIImage(ciImage: scaledCIImage)
       
        let imageData = uiimage.pngData()!
        let docDir = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
        let dataNow = "\(Date.now).png"
        let imageURL = docDir.appendingPathComponent(dataNow)
        try! imageData.write(to: imageURL)
         
        _ = UIImage(contentsOfFile: imageURL.path)!
        UIImageWriteToSavedPhotosAlbum(uiimage, nil, nil, nil)
      }
    }
  }

You're saving the image to the user's document directory, which is not the same as the photo library.

The API for the photo library is documented here: (https://developer.apple.com/documentation/photokit/phphotolibrary).

save image to gallery swiftui
 
 
Q