Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A tap on the screen of the camera view should take a picture and save to the photos library #15

Open
truedat101 opened this issue Jul 25, 2022 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@truedat101
Copy link
Member

truedat101 commented Jul 25, 2022

Add a tap gesture for saving a photo. Photos should save to phone photo library.

@truedat101
Copy link
Member Author

So @AdAstraCA this is really the main one I'd like to get finished and we can wrap up on this for now.

@eibarolle
Copy link
Contributor

I can finish this soon. By the way, I managed to get my Arduino set up on my Mac. Once I finish up the camera's consistency, I can start straight away on the Bluetooth/Arduino work.

@truedat101
Copy link
Member Author

Will review.

@truedat101 truedat101 added the bug Something isn't working label Aug 12, 2023
@truedat101
Copy link
Member Author

Still doesn't work. Can you confirm :

  • where should it be saving the photos
  • please show me the code associated with the photo save
  • Are there permissions needed to access photo library
  • have you checked that there are not missing files that need to be checked in

@eibarolle
Copy link
Contributor

  1. The photos are saved in the camera roll. I can confirm that on my end, when the white circle button below the actual camera is clicked, the photos are saved there. The actual filter buttons do not act as photo taking buttons.

  2. func savePic(){
    print("saving")
    guard let image = UIImage(data: self.picData) else{return}

     // saving Image...
     UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
     
     self.isSaved = true
     
     print("saved Successfully....")
    

    }
    However, the photo has to be processed first. To mitigate this, I added a 0.5 second wait for the photo to process. The problem on your end could be your phone not processing it enough. The obvious fix is to add a longer wait, but I'll also try finding one with a better stopgap. The wait is seen below.
    func takePic(){
    print("success")
    self.output.capturePhoto(with: AVCapturePhotoSettings(), delegate: self)
    let timer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: false) { (timer) in
    self.savePic()
    }
    }

  3. Yes, they are initialized in the camera model(specifically in Check()).
    class CameraModel: NSObject, ObservableObject, AVCapturePhotoCaptureDelegate{
    @published var isTaken = false
    @published var session = AVCaptureSession()
    @published var alert = false
    @published var isSaved = false
    @published var output = AVCapturePhotoOutput()
    @published var preview: AVCaptureVideoPreviewLayer!
    @published var picData = Data(count: 0)

    func Check(){
    switch AVCaptureDevice.authorizationStatus(for: .video){
    case .authorized:
    setUp()
    return
    case .notDetermined:
    AVCaptureDevice.requestAccess(for: .video) { status in
    if status {
    self.setUp()
    }
    }
    case .denied:
    self.alert.toggle()
    return
    default:
    return
    }
    }

    func setUp(){
    do{
    self.session.beginConfiguration()

         //let device = AVCaptureDevice.default(.builtInDualCamera, for: .video, position: .back)
         
         guard let device = AVCaptureDevice.default(for: AVMediaType.video) else {
             return
         }
         let input = try AVCaptureDeviceInput(device: device)
         
         //checking and adding to session
         
         if self.session.canAddInput(input){
             print("input")
             self.session.addInput(input)
         }
         
         //same for output
         
         if self.session.canAddOutput(output){
             print("output")
             self.session.addOutput(self.output)
         }
         
         self.session.commitConfiguration()
         
     }catch{
         print(error.localizedDescription)
     }
    

    }

  4. All of the files are checked in.
    Side Note: For the show/hide and color buttons, I can confirm that they work on my end, but you have to change to another filter for the changes to take effect. However, I'm trying to find a way to update the current filter, and I'm also considering your end might be due to layout changes.

@eibarolle
Copy link
Contributor

The CameraPreview also had a warning, but you noted that already, and I'm working on a fix.

@truedat101
Copy link
Member Author

So there are two bugs:

  • The Permission to access Photo Library happens only once, and only happens when you take a picture. Always request this permission if it isn't set, and don't take a picture if it isn't set.
  • The file save in the photos library is just a raw camera photo, it doesn't contain the filter view.

Please verify the fixes before submitting. The easiest way to get the dialog again for permissions is to delete the app .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants