0

I am developing a Log-In screen using XCode 15.2 and the latest version of SwiftUI that is shipped in Xcode.

The Simulator I use is the iPhone 15 Pro.

The Log-In Screen has two TextFields one contains the Users Email Address and the other is a SecureField which is used for the Password.

The code for the TextFields are:

TextField("Email Address", text: $userData.Email)
                        .frame(width: UIScreen.main.bounds.width - 100)
                        .textFieldStyle(.roundedBorder)
                        .textInputAutocapitalization(.never)
                        .opacity(0.8)

SecureField("Password", text: $userData.Password)
                        .frame(width: UIScreen.main.bounds.width - 100)
                        .textFieldStyle(.roundedBorder)
                        .opacity(0.8)

When I run this in the Simulator, all looks fine, but as soon as I click into either TextField, I see the following in the Debug area.

Error for queryMetaDataSync: 2
Error for queryMetaDataSync: 2
Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x6000021735c0 'accessoryView.bottom' _UIRemoteKeyboardPlaceholderView:0x106839040.bottom == _UIKBCompatInputView:0x1068374d0.top   (active)>",
    "<NSLayoutConstraint:0x6000021623f0 'assistantHeight' SystemInputAssistantView.height == 45   (active, names: SystemInputAssistantView:0x10681fc80 )>",
    "<NSLayoutConstraint:0x6000021731b0 'assistantView.bottom' SystemInputAssistantView.bottom == _UIKBCompatInputView:0x1068374d0.top   (active, names: SystemInputAssistantView:0x10681fc80 )>",
    "<NSLayoutConstraint:0x600002173110 'assistantView.top' V:[_UIRemoteKeyboardPlaceholderView:0x106839040]-(0)-[SystemInputAssistantView]   (active, names: SystemInputAssistantView:0x10681fc80 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600002173110 'assistantView.top' V:[_UIRemoteKeyboardPlaceholderView:0x106839040]-(0)-[SystemInputAssistantView]   (active, names: SystemInputAssistantView:0x10681fc80 )>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

I don't understand what is driving this error. Reading the error it mentions 'remote keyboard'

What does get my attention is the following line:

"<NSLayoutConstraint:0x6000021623f0 'assistantHeight' SystemInputAssistantView.height == 45   (active, names: SystemInputAssistantView:0x10681fc80 )>"

I don't know if something needs to be a height of 45 or I have set a height of 45 somewhere, which I am unable to find anywhere.

What can I try next?

3
  • Are you trying to mix SwiftUI and UIKit together? Commented Mar 20, 2024 at 10:10
  • add the keyboardtype to the textfield like TextField("Email Address", text: $userData.Email).keyBoardType(.emailAddress) Commented Mar 20, 2024 at 10:31
  • No son, no UIKit Imported. NewbieiOS, I gave that a try but the same results. Commented Mar 20, 2024 at 15:18

1 Answer 1

0

Let's say you have three different views,

  1. UIRemoteKeyboardPlaceholderView
  2. UIKBCompatInputView
  3. SystemInputAssistantView

And you added four constraints between these three views,

  1. UIRemoteKeyboardPlaceholderView's bottom edge should equal UIKBCompatInputView's top edge.
  2. SystemInputAssistantView's height should equal 45.
  3. SystemInputAssistantView's bottom edge should equal UIKBCompatInputView's top edge.
  4. SystemInputAssistantView's top edge should equal UIRemoteKeyboardPlaceholderView's bottom edge.

Problem in your constraints

  1. As per your constraints, 3rd and 4th constraint signifies that your SystemInputAssistantView should be in between UIKBCompatInputView and UIRemoteKeyboardPlaceholderView
  2. 1st constraints signifies that UIKBCompatInputView should be at immediate bottom of UIRemoteKeyboardPlaceholderView

And, that is why you are having constraint issues between three of your views. The layout engine is getting confused between these two constraints as it doesn't know which constraint should have a higher priority.

Try and remove one of the constraints (either 1st one or 3rd and 4th one)and it should work fine.

Here is a useful site that you can use to visualise your constraints, WTF Auto Layout

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks Prati, yea, there are one other view that uses TextInput. I will have a geez and see if I can see any differences. I will keep you posted.
I had a quick look Pratik, and NO, there is no other View that contains TextInput, so, are you able to have a gander at the code if I was to send it to you?
Sure, I can do that
I saw your code, and it looks all good to me. The issue is with SystemInputAssistantView of the iPhone's keyboard. I think it is a known issue, you can ignore this warning. Here are some of the articles you can refer, developer.apple.com/forums/thread/741934 stackoverflow.com/questions/61773693/…
Thanks Pratik, you have been a huge help with this. Much appreciated. I see there is an Xcode update which I will install first and see how it goes. As long as my code is OK. That is what I was worried about. Pete
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.