Saving Photo with Feedback
Instagram Firebase
Assuming the user is satisfied with their photo taken, let's enable the option to save it into their albums for later use. The new Photos framework released in iOS 9+ allows us to very easily save photos into a user's device with just a few calls. Once it is saved, we'll present an interesting animation of text as visual feedback.

Comments (17)
Hen Shabat
6 years ago
Hi Brian, You will take care for: photoSampleBuffer! previewPhotoSampleBuffer! imageData! with guard? Thanks!
Brian Voong
6 years ago
Hen Shabat
6 years ago
Hi Brian, Another little question please: Can we handle the switch between frond and back cameras? If you already have another tutorial for this just let me know please. Thanks!
faraz
6 years ago
Hi Brian, there seems to be a bug in my code that every time I share a photo it appears multiple times on the home feed. Any idea why?
Brian Voong
6 years ago
Morris Liao
6 years ago
I have the same problem. How do you empty the posts array?
xd573797483
6 years ago
thats because you called two times fetchPostsWithUser().
TTTTgg
6 years ago
Hi Brian, each time i saved the photo, in select photo view, there will be some duplicate photos. But when i restart the app, those duplicate photos disappeared, it's similar to faraz's post. So any way to fix this without quitting the app each time?
TTTTgg
6 years ago
Hi Brian, Ive solved it, because I missed a option value in PhotoSelectorController. And i compared your code with mine so i found where i was wrong.
Laurent Maquet
5 years ago
Hi Brian, I'm wondering why, this time, you don't need to instantiate saveButton and cancelButton with lazy var ? Their target needs "self" which shouldn't be available before init ?
Brian Voong
5 years ago
Laurent Maquet
5 years ago
Brian, sorry it's me again... When we setup the capture session, we finish with the following : previewLayer.frame = view.frame What if we rotate the device? : the view will layout, but previewLayer.frame will keep the same. How would you manage this issue? Is there a way to ensure autolayout when working with frames ?
Brian Voong
5 years ago
wealthnut79
5 years ago
Hey Brian, how do i know if my camera code is working if i only have the simulator? Showing camera Capturing photo... Capturing photo... This is all i see in the debugger
Brian Voong
5 years ago
Anirudh Bandi
5 years ago
there is a noticeable difference in the quality of the photos taken by the camera in the app and the ones taken by the normal camera app. Why is that the case?
Abhishesh
5 years ago
I'm guessing this is because we are compressing the image.
tetraprism95
5 years ago
Hey Brian, I'm having a problem with the Photo Saved "savedLabel.center = self.center". When I press the save button, the frame is placed in center, but the text label isn't. It's more on the left side of the frame then in the middle. Any reason why that is? Thanks a lot your tutorials rock!
tetraprism95
5 years ago
Nevermind, I figured it out. For some reason, unlike in your code, I'd have to implement another property where I do this savedLabel.textAlignment = .center
tetraprism95
5 years ago
Maybe you did explain this later in the video, I was commenting midway sorry.
AlfieLBTA
5 years ago
Hello , Does anyone knows why my image returns very small inside my button: (Xcode 9.4 -> Swift 4) btn.setImage(#imageLiteral(resourceName: "camera-save-photo-btn").withRenderingMode(.alwaysOriginal), for: .normal) btn.addTarget(self, action: #selector(handleSave), for: .touchUpInside) btn.imageView?.contentMode = .scaleAspectFit In order to make it fit a proper size i need to make the assets 3 times bigger than it should.
ngsison
4 years ago
Hi Brian, let cancelButton: UIButton = { let button = UIButton(type: .custom) button.setImage(#imageLiteral(resourceName: "cancel_shadow"), for: .normal) button.addTarget(self, action: #selector(onCancelButtonPress), for: .touchUpInside) return button }() Do you know any possible reason why the onCancelButtonPress is not firing up? The declaration is like this: @objc private func onCancelButtonPress() { print("CANCEL BUTTON PRESSED") } I encountered the same case where the event is not firing up on optionsButton in HomePostCell, I fixed it by adding the target after anchoring the optionsButton. I tried adding the cancelButton event after setting the anchor but it doesn't work. I also tried setting it as lazy var, doesn't work either.
ngsison
4 years ago
ngsison
4 years ago
ngsison
4 years ago
Haha, nevermind, it doesn't work because I added it as subView of photoPreviewImageView instead of adding it as subView of the actual root view
Brian Voong
4 years ago
BTol Mohammad
4 years ago
Hi Brin, How can I make a button that takes the photo and goes to another viewController to upload​ the photo and the description to firebase?
Brian Voong
4 years ago
BTol Mohammad
4 years ago
Thank you for answering promptly, but I want to do it from the PreviewPhotoContainerView where there will be three buttons not only the cancel button and the save button but also a button that take you to another controller
Brian Voong
4 years ago
BTol Mohammad
4 years ago
could not figure out how that done. Can you provide example to help me in moving from uiview to uiviewcontroller? Thank you
Brian Voong
4 years ago
BTol Mohammad
4 years ago
This is what I did but nothing worked ): var myViewController: AdPostingViewController? and in the button I added this myViewController?.navigationController?.pushViewController(AdPostingViewController(), animated: true) I am trying to go to AdPostingViewController from the PreviewPhotoContainerView when I press a button
Brian Voong
4 years ago
ncytimothy
4 years ago
For those who are wondering what #if (!arch(x86_64)) is in the updated project: this is to prevent the simulator to run the code when it does not have an active camera #if (!arch(x86_64)) guard let previewFormatType = settings.availablePreviewPhotoPixelFormatTypes.first else { return } settings.previewPhotoFormat = [kCVPixelBufferPixelFormatTypeKey as String: previewFormatType] output.capturePhoto(with: settings, delegate: self) #endif Example: https://swiftunboxed.com/internals/targetenvironment-platform-condition/ #if (arch(x86_64) || arch(i386)) && os(iOS) // Simulator! #endif
rgarcia
4 years ago
Hi Brian, thanks for amazing content and ver explained course, for people trying with iPhone 10 when capture the picture with the camera its change the dimension, it can be fixed modifying the previewImageView in the PreviewPhotoContainerView like this: let previewImageView: UIImageView = { let iv = UIImageView() iv.contentMode = .scaleAspectFill return iv }()
frankcrest
4 years ago
great find
malrhex
4 years ago
PhotoOutput method on CameraController is out of date. 'jpegPhotoDataRepresentation(forJPEGSampleBuffer:previewPhotoSampleBuffer:)' was deprecated in iOS 11.0: Use -[AVCapturePhoto fileDataRepresentation] instead.
Brian Voong
4 years ago
malrhex
4 years ago
It is actually the updated code. btw, there is a bug with the course #28. and please try this scenario: 1) Follow someone and hit refresh (So the homeFeed will have his content). 2) Look for him again, and then hit Unfollow. 3) Jump straight from the search from the unfollow view to the homeFeed and hit Refresh!
Cinquain
4 years ago
That video was cocaine good
Brian Voong
4 years ago
bangkm
3 years ago
There are more than 10,000 photos on the device. There are so many pictures that it takes a long time to load so you can't see them in the cell?
HELP & SUPPORT