Mijick / CameraView

Camera made simple (SwiftUI)
MIT License
47 stars 7 forks source link

App lifecycle problems #26

Open clbemre opened 1 week ago

clbemre commented 1 week ago

Hello, firstly this is a great framework.

I have a problem. When the application goes to the background and comes to the front again, the image or video preview closes and returns to the shooting screen, this is a problem, the second problem is that when I try to shoot again after this scenario, I get a crash.

Why doesn't the app continue where I left off when I put it in the background and then bring it back to the foreground?

var cameraView: UIView { cameraLayer.superview ?? .init() } -> and i get a crash for take a picture after background/foregroung. Because I guess CameraInputView is being recreated.

Thank you

FulcrumOne commented 1 week ago

Hey @clbemre, thanks for this ticket!

I'm currently busy developing an update for our other library (NavigationView), but I'll be back here as soon as I finish that task (probably at the end of this week).

I hope it suits you, thanks again for your ticket and have a nice day, T.K.

clbemre commented 1 week ago

Hello again @FulcrumOne, thank you for your interest.

Additionally, when there is a CameraPreview screen displayed, if I display an alert on the screen with MJCameraController().alert { }, the CameraPreview closes. I want to maintain its state and prevent the preview screen from closing unless I close it myself. I get the same alert problem if I present it with .alert {} in Camera Preview.

The alert appears on the preview screen, but this situation when the cancel button is pressed. So, disappeared preview screen.

I think this alert problem and the background/foreground problem of the application that I mentioned before are caused by the same problem.


Additionally, I’m just curious, why do you use DispatchQueue.main.async { [self] in } instead of DispatchQueue.main.async { [weak self] in } ?

clbemre commented 6 days ago

Hello again @FulcrumOne, when will you fix these issues? or will?

Thank you.

FulcrumOne commented 6 days ago

hey @clbemre,

Sorry, had a lot of work related to our other libraries. In my calendar, work on this library is scheduled to start this Thursday CleanShot 2024-07-01 at 10 44 38

Apologies for the "communication issues" once again; I believe creating a Discord / Slack channel would help us stay better connected and updated on things related to libraries. I'll try to organize it this week πŸ˜‰

Have a great day, Tomasz K.

clbemre commented 6 days ago

Thank you @FulcrumOne , I will be waiting for your response. Thank you for your interest. πŸ™πŸ»

Have a nice day. Best Regards

clbemre commented 3 days ago

Hello again, @FulcrumOne , have you started this issues solutions? I'm sorry for bothering you but its a little important for me :) Thank you again.

FulcrumOne commented 3 days ago

Hey, I'm starting this eveningπŸ˜‰ Hope it will be ready by the weekend

clbemre commented 3 days ago

This is great! Thank you :) Good luck :)

FulcrumOne commented 3 days ago

Hello, firstly this is a great framework.

I have a problem. When the application goes to the background and comes to the front again, the image or video preview closes and returns to the shooting screen, this is a problem, the second problem is that when I try to shoot again after this scenario, I get a crash.

Why doesn't the app continue where I left off when I put it in the background and then bring it back to the foreground?

var cameraView: UIView { cameraLayer.superview ?? .init() } -> and i get a crash for take a picture after background/foregroung. Because I guess CameraInputView is being recreated.

Thank you

hey @clbemre, just to confirm - you're telling that you experienced a crash when you backgrounded the app and then returned to the foreground, correct?

FulcrumOne commented 3 days ago

@clbemre, that second problem (with alert and crash I was able to reproduce, so I'll start from this one)

clbemre commented 3 days ago

Hello again @FulcrumOne First of all, there are a few problems; after the first startup, it puts it in the background without doing anything, and when it comes back to the foreground, it crashes while trying to take a photo/video. Then, after showing an alert while on the preview screen, both the preview screen disappears and when I try to take a photo or video again, it crashes again, and sometimes it is because of the cameraView superView and sometimes it is because of the blurViews, but I think the problem is common, because as far as I understand, the camera manager is deinit/init and the swiftUI randomly appears on the screen. because of their renderings.

Additionally , independently of these, the snapshot and blurview you showed while flipping the camera are turned landscape.

Sorry for my english, sometimes i use translate :)

FulcrumOne commented 3 days ago

hey @clbemre,

No problem, English is not my native language either (it would be nice if we both spoke Polish πŸ˜…)

Could you please test the branch called 'patch-1.2.1', it should fix your problem with alert that causes the app to crash? You should also add this method to your MCameraController - .equatable() (it's a temporary solution) CleanShot 2024-07-04 at 19 36 35

clbemre commented 2 days ago

Hey @FulcrumOne this temporary solution works. Thank you. πŸ’ͺ🏻 (we can't speak Polish, I'm Turkish πŸ˜€) Are we going to continue with this temporary solution or are you continuing to work on resolving the issue at its base? As far as I can see, you are working on memory leaks in particular.

FulcrumOne commented 2 days ago

hey @clbemre, thanks for letting me know!

I want to spend some time today and check the library for problems with memory leaks, and then I will move on to fixing this issue with the background mode.

clbemre commented 2 days ago

Hey @FulcrumOne , also we have a little problem :) when First launch MCameraController, the system want to permission. If I deny the system permission, the UI does not update and switch to the error view, the camera layer visible black view.

IMG_F5B502CD1829-1

FulcrumOne commented 2 days ago

@clbemre I'll have to spend little more time on this task, as the problem is little bigger than I initially thought; there are several problems that I discovered today. I'll keep you in the loopπŸ˜‰

clbemre commented 1 day ago

okey @FulcrumOne thank you for your response. I'll be wating for you. Good luck :)

FulcrumOne commented 1 day ago

Hey @clbemre,

So we have two potential solutions to our problem:

  1. We can move CameraManager to the level above (i.e. the parent view in which MCameraController is implemented, managed by the developer). Additionally if we opt for this option, I would also like to move the functions from the Public+MCameraController file lines 15 -> 43 to the CameraManager initialiser.
  2. We can make CameraManager singleton; this will allow us to avoid major changes to the public API, however, there may be some issues when trying to port the library to iPadOS and macOS.

Therefore, I think that, in the long term, a better solution will be to implement point 1. What do you think?

FulcrumOne commented 10 hours ago

@clbemre,

The branch named patch-1.2.1-beta contains fixes to the following problems:

  1. MCameraController and error screen
  2. Alert interrupting camera session
  3. Memory leaks when app switches to and from the background mode
FulcrumOne commented 9 hours ago

Hello, firstly this is a great framework.

I have a problem. When the application goes to the background and comes to the front again, the image or video preview closes and returns to the shooting screen, this is a problem, the second problem is that when I try to shoot again after this scenario, I get a crash.

Why doesn't the app continue where I left off when I put it in the background and then bring it back to the foreground?

var cameraView: UIView { cameraLayer.superview ?? .init() } -> and i get a crash for take a picture after background/foregroung. Because I guess CameraInputView is being recreated.

Thank you

I cannot reproduce this problem unfortunately. However, there is a chance that this branch has already fixed the issue. If not, please let me know

clbemre commented 9 hours ago

@FulcrumOne Hello, Is the temporary solution not sufficient at the moment? Also I think long term solution is better.

FulcrumOne commented 9 hours ago

Additionally , independently of these, the snapshot and blurview you showed while flipping the camera are turned landscape.

I'm working on this now. If you need a faster solution, I strongly recommend locking the rotation for the current screen (lockOrientation method).

clbemre commented 9 hours ago

Additionally , independently of these, the snapshot and blurview you showed while flipping the camera are turned landscape.

I'm working on this now. If you need a faster solution, I strongly recommend locking the rotation for the current screen (lockOrientation method).

I noticed this about this problem. When I tested it on the iPhone X, it rotates, but when I tested it on the iPhone 11 Pro Max, it does not rotate. I also completely turned off the device rotation, it only works in portrait mode.

FulcrumOne commented 9 hours ago

@FulcrumOne Hello, Is the temporary solution not sufficient at the moment? Also I think long term solution is better.

  • patch-1.2.1-beta solutions is finished or will?
  • var cameraView: UIView { cameraLayer.superview ?? .init() } -> It got resolved after applying the equatable() workaround.
  • Actually after I applying the equatable() all problems resolved. I guess just have a little memory leak, thats all.

This temporary solution was a bit unstable and caused other problems (the error screen was not displayed for example). I would therefore recommend using the patch-1.2.1-beta branch πŸ˜‰

clbemre commented 9 hours ago

@FulcrumOne Hello, Is the temporary solution not sufficient at the moment? Also I think long term solution is better.

  • patch-1.2.1-beta solutions is finished or will?
  • var cameraView: UIView { cameraLayer.superview ?? .init() } -> It got resolved after applying the equatable() workaround.
  • Actually after I applying the equatable() all problems resolved. I guess just have a little memory leak, thats all.

This temporary solution was a bit unstable and caused other problems (the error screen was not displayed for example). I would therefore recommend using the patch-1.2.1-beta branch πŸ˜‰

Okey I will, thank you for your interest and for this great library :)

FulcrumOne commented 9 hours ago

Thanks! If you have any further problems, let me knowπŸ˜‰

PS. Check out our other solutions too!