Error creating an image format with an unknown type - swift

While choosing an image from the image picker in iOS 10, I am getting an error - Creating an image format with an unknown type is an error
Here is my code:
func CamaraInit(){
let isOk = UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera)
if isOk {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.cameraDevice = .rear
imagePicker.showsCameraControls = true
imagePicker.allowsEditing = true
imagePicker.cameraCaptureMode = .photo
// imagePicker.cameraCaptureMode = .video
self.present(imagePicker, animated: true, completion: nil)
}
}
func imageInit(){
let isOk = UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary)
if isOk {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
//imagePicker.allowsEditing = true
self.present(imagePicker, animated: true, completion: nil)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
var useImage : UIImage!
let originalImage = info[UIImagePickerControllerOriginalImage] as! UIImage
let editedImage = info[UIImagePickerControllerEditedImage] as? UIImage
if editedImage == nil {
useImage = originalImage
} else {
useImage = editedImage
}
if picker.sourceType == UIImagePickerControllerSourceType.camera {
UIImageWriteToSavedPhotosAlbum(useImage, nil, nil, nil)
}
self.UIPhotoImage = useImage
self.viewChange()
picker.dismiss(animated: true, completion: nil)
}
I have searched a lot of materials but still have no idea why.

seems it is kind of warning not error,at least in my case...after uploading your image,viewWillApear will be automatically called again.
thats why you think image was not uploaded.

Related

All sounds in the app are muted after using the image picker

All sounds in the app are muted after using the image picker
There is no separate volume setting when loading the image picker.
Why is this?
my code
#IBAction func tapRecording(_ sender: UIButton) {
if UIImagePickerController.isSourceTypeAvailable(.camera) {
imagePicker.delegate = self
imagePicker.sourceType = .camera
imagePicker.mediaTypes = [kUTTypeMovie as String]
imagePicker.videoMaximumDuration = 120 // or whatever you want
imagePicker.videoQuality = .typeMedium
imagePicker.allowsEditing = false
player.pause()
playButton.isHidden = false
exampleLabel.isHidden = false
self.navigationController?.present(imagePicker, animated: true)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
dismiss(animated: true, completion: nil)
let videoURL = info[.mediaURL] as! URL
let vc = UIStoryboard(name: "Growth", bundle: nil).instantiateViewController(identifier: "GrowthSaveViewController") as? GrowthSaveViewController
vc!.videoUrl = videoURL
vc?.videoData = videoData
self.navigationController?.pushViewController(vc!, animated: true)
}

video imagePickerController cancel not working

I am using custom CropViewController open source imagePicker for photos, and for video I'm trying to use default imagePicker provided by Swift itself since CropViewController doesn't have video option.
After I pick a video from photo library, three buttons shown at the bottom (cancel, play, select). Play button and select button works perfectly but cancel won't work.
Here is my code to trigger imagePickerController for both photo and video.
#objc func videoPresentPicker() {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .photoLibrary
picker.mediaTypes = [kUTTypeMovie as String]
picker.allowsEditing = true
self.present(picker, animated: true, completion: nil)
}
#objc func photoPresentPicker() {
self.croppingStyle = .default
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .photoLibrary
picker.allowsEditing = false
self.present(picker, animated: true, completion: nil)
}
I am truly appreciated for you help. I have been struggling for few days and finally reaching out for some helps...
Update
extension ChatViewController: CropViewControllerDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
internal func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
dismiss(animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let videoUrl = info[UIImagePickerController.InfoKey.mediaURL] as? NSURL {
let data = NSData(contentsOf: videoUrl as URL)!
print("File size before compression: \(Double(data.length / 1048576)) mb")
let compressedURL = NSURL.fileURL(withPath: NSTemporaryDirectory() + NSUUID().uuidString + ".m4v")
self.compressVideo(inputURL: videoUrl as URL, outputURL: compressedURL) { (exportSession) in
guard let session = exportSession else {
return
}
switch session.status {
case .unknown:
break
case .waiting:
break
case .exporting:
break
case .completed:
guard let compressedData = NSData(contentsOf: compressedURL) else {
return
}
print("File size after compression: \(Double(compressedData.length / 1048576)) mb")
case .failed:
break
case .cancelled:
break
#unknown default:
break
}
}
} else {
guard let image = (info[UIImagePickerController.InfoKey.originalImage] as? UIImage) else { return }
let cropController = CropViewController(croppingStyle: croppingStyle, image: image)
cropController.delegate = self
imageView.image = image
picker.dismiss(animated: true, completion: {
self.present(cropController, animated: true, completion: nil)
if self.inputTextField.isFirstResponder == true {
self.handleKeyboardWillShow()
}
})
}
transparentView.alpha = 0
self.tableView.frame = CGRect(x: 0, y: 0, width: 0, height: 0)
dismiss(animated: true, completion: nil)
}
Just implement this function
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
dismiss(animated:true, completion: nil)
}

How can I make this imagePickerController able to accept edited images?

How can I make this imagePickerController able to accept edited images?
When selecting an image and adjusting it (zoom in and out) and selecting done, the image reverts back to its original state. What can I add to to my code to have the zoomed image save and show up in my image view?
The following is my code so far:
let cameraRollAction = UIAlertAction(title: "Camera Roll", style: .default) { (action) in
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary) {
let picker = UIImagePickerController()
picker.delegate = self
picker.allowsEditing = true
picker.mediaTypes = [kUTTypeImage as String]
picker.sourceType = UIImagePickerControllerSourceType.photoLibrary
self.present(picker, animated: true, completion: nil)
self.newPic = false
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let mediaType = info[UIImagePickerControllerMediaType] as! NSString
if mediaType.isEqual(to: kUTTypeImage as String) {
let selectedImage = info[UIImagePickerControllerOriginalImage] as! UIImage
profileImageView.image = selectedImage
if newPic == true {
UIImageWriteToSavedPhotosAlbum(selectedImage, self, #selector(imageError), nil)
}
}
self.dismiss(animated: true, completion: nil)
}
Instead of
UIImagePickerControllerOriginalImage
use
UIImagePickerControllerEditedImage
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let mediaType = info[UIImagePickerControllerMediaType] as! NSString
if mediaType.isEqual(to: kUTTypeImage as String) {
let selectedImage = info[UIImagePickerControllerEditedImage] as! UIImage ?? info[UIImagePickerControllerOriginalImage] as! UIImage // will return original image if edited image is not available
profileImageView.image = selectedImage
if newPic == true {
UIImageWriteToSavedPhotosAlbum(selectedImage, self, #selector(imageError), nil)
}
}
self.dismiss(animated: true, completion: nil)
}

Save user profile picture to firebase

Good Afternoon, I am trying to allow users to save their profile picture in firebase. my application runs without a crash. however, when I select a picture it doesn't save to the system. I have a ViewController, and an extension file that I have been placing my code in. I will place below. Please help me understand what I am doing wrong. Hopefully, this question will help others who are facing the same issues.
import UIKit
import Firebase
class EditProfileVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
setupProfileImageView()
self.view.backgroundColor = UIColor.white
}
func setupProfileImageView() {
view.addSubview(profileImageView)
profileImageView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
profileImageView.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 100).isActive=true
profileImageView.widthAnchor.constraint(equalToConstant: 120).isActive = true
profileImageView.heightAnchor.constraint(equalToConstant: 120).isActive = true
profileImageView.layer.cornerRadius = 60
profileImageView.layer.masksToBounds = true
var randomString = UUID().uuidString
let storageRef = Storage.storage().reference().child;"\(randomString).png")
if let uploadImage = UIImagePNGRepresentation(self.profileImageView.image!) {
storageRef.putData(uploadImage, metadata: nil) { (metadata, error) in
if error != nil {
print("Error upload data to Firebase Storage. Detail: \(String(describing: error))")
return
}
if let profileImageURl = metadata?.downloadURL()?.absoluteString {
self.registerUser(UserId: userId, profileImageURL: profileImageURL) {
}
}
}
}
}
lazy var profileImageView: UIImageView = {
let imageView = UIImageView()
imageView.image = UIImage(named: "users")
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.contentMode = .scaleAspectFill
imageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleSelectProfileImageView)))
imageView.isUserInteractionEnabled = true
return imageView
}()
}
// This is my extension file
import UIKit
import Firebase
extension EditProfileVC: UIImagePickerControllerDelegate, UINavigationControllerDelegate{
#objc func handleSelectProfileImageView() {
let picker = UIImagePickerController()
picker.delegate = self
picker.allowsEditing = true
present(picker, animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
var selectedImageFromPicker: UIImage?
dismiss(animated: true, completion: nil)
if let editedImage = info["UIImagePickerControllerEditedImage"] {
selectedImageFromPicker = editedImage as? UIImage
} else if let originalImage = info["UIImagePickerControllerOriginalImage"] {
selectedImageFromPicker = originalImage as? UIImage
}
if let selectedImage = selectedImageFromPicker {
profileImageView.image = selectedImage
}
print(info)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
print("Canceled Picker")
dismiss(animated: true, completion: nil)
}
}
My app doesn't crash when I run it. It's just no images are stored in firebase. I want users to click onto the EditProfileVC, then be able to change their profile picture and have it save. If anyone can help me solve this issue, it would be greatly appreciated.

Can't save recorded video

I've got really strange problem and can't solve it.
I'm recording video through the UIImagePicker
This is my code of the recording :
func takeVideo(_ sender: Any) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera){
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.mediaTypes = [(kUTTypeMovie as NSString) as String]
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.allowsEditing = false
imagePicker.showsCameraControls = true
//imagePicker.videoMaximumDuration = Double(seconds)
self.present(imagePicker, animated: true, completion: nil)
}else{
noCamera()
}
}
And this one is supposed to save the video :
func videoPickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: NSDictionary!) {
let tempImage = info[UIImagePickerControllerMediaURL] as? NSURL
let pathString = tempImage?.relativePath
self.dismiss(animated: true, completion: nil)
UISaveVideoAtPathToSavedPhotosAlbum((pathString)!, self, nil, nil)
}
My problem is that it lets me to record the video but cant click either of the buttons Retake, Play or Use Video
This is how it looks like after recording video