Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIAlertController and UIViewAlertForUnsatisfiableConstraints error

Tags:

I upgraded to Xcode 10.2 yesterday and started using Swift 5 and notice this error when bringing up my UIAlertController photo prompt. I don't remember seeing it in Xcode 10.1

Will attempt to recover by breaking constraint  <NSLayoutConstraint:0x600001321e00 UIView:0x7fe1246070a0.width == - 16   (active)>  Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. 

I read this issue How to trap on UIViewAlertForUnsatisfiableConstraints? and was able to pin point the error to my UIAlertController (highlighted in red)

enter image description here

Here's my code:

  @objc private func promptPhoto() {      let prompt = UIAlertController(title: "Choose a Photo",                                    message: "",                                    preferredStyle: .actionSheet)      let imagePicker = UIImagePickerController()     imagePicker.delegate = self      let camerAction = UIAlertAction(title: "Camera", style: .default) { _ in       guard self.isCameraAccessible() else {         self.showAlert(title: "Oops", message: "Camera is not available")         return       }       imagePicker.sourceType = .camera       imagePicker.allowsEditing = true       self.present(imagePicker, animated: true)     }      let libraryAction = UIAlertAction(title: "Photo Library", style: .default) { _ in       imagePicker.sourceType = .photoLibrary       imagePicker.allowsEditing = true       self.present(imagePicker, animated: true)     }      let cancelAction = UIAlertAction(title: "Cancel",                                      style: .cancel,                                      handler: nil)      prompt.addAction(camerAction)     prompt.addAction(libraryAction)     prompt.addAction(cancelAction)      present(prompt, animated: true) {       // Prevent closing the prompt by touch up outside the prompt.       prompt.view.superview?.subviews[0].isUserInteractionEnabled = false     }    } 

I've tried playing around setting the width of my UIAlertController by using this code inside my promptPhoto() method to no avail.

let width: NSLayoutConstraint = NSLayoutConstraint(item: prompt.view!,                                                    attribute: NSLayoutConstraint.Attribute.width,                                                    relatedBy: NSLayoutConstraint.Relation.equal,                                                    toItem: nil,                                                    attribute: NSLayoutConstraint.Attribute.notAnAttribute,                                                    multiplier: 1,                                                    constant: self.view.frame.width)   prompt.view.addConstraint(width)  

Is there a way to control the UIAlertController width so that I could get rid of my error message?

Thank you in advance.

like image 912
bvh Avatar asked Mar 28 '19 07:03

bvh


People also ask

How do I create a UIView alert for unsatisfiable constraints?

Open the Breakpoint Navigator cmd+7 ( cmd+8 in Xcode 9) Click the Add button in the lower left. Select Add Symbolic Breakpoint... Where it says Symbol just type in UIViewAlertForUnsatisfiableConstraints. You can also treat it like any other breakpoint, turning it on and off, adding actions, or log messages. Share.

How do I configure alerts and action sheets in UIKit?

Use this class to configure alerts and action sheets with the message that you want to display and the actions from which to choose. After configuring the alert controller with the actions and style you want, present it using the present (_:animated:completion:) method. UIKit displays alerts and action sheets modally over your app's content.

Can the uialertcontroller class be subclassed?

The UIAlertController class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.

Why does the alert controller have a reference to each field?

The alert controller maintains a reference to each text field so that you can access its value later. The UIAlertController class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.


1 Answers

This may be a Xcode bug.Still apple haven't fix that.this error occurred latest xcode 11.3.1 also

like image 173
Dilan Avatar answered Nov 03 '22 00:11

Dilan