UIAlertController and UIViewAlertForUnsatisfiableConstraints error
Asked Answered
C

1

22

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.

Confute answered 28/3, 2019 at 7:1 Comment(6)
In your Build Setting -> Swift Compiler - Language using Swift 5 or Swift 4.2 ?Silvery
@Silvery The Swift Language Version is set to Swift 5Confute
I'd say don't worry about it, this seems like an internal layout inconsistency in UIAlertController.Arthropod
This seems to be a bug: openradar.appspot.com/49289931Tarry
Is there still no fix for this? Keeps printing errorNamnama
Anyone find solution for mentioned issue?Tamikatamiko
F
2

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

Fullmouthed answered 12/3, 2020 at 17:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.