Find all layout constraint issues while debugging - ios

I'm looking for a way I can find all UI related constraint issues while debugging my iOS app. I recently faced an issue in my production app that a UI constraint was failing and it caused an issue only on iPhone 8+. I didn't realise it while testing as even though that constraint failed on all devices, it still worked on my testing device.
Is there a strict mode which I can enable for development which would crash the app on any device if there is any constraint issue ?

Any unsatisfiable constraints will be reported in the console. If your console is too noisy, that's a separate problem, but if you really want to get slapped in the face, you can set a symbolic breakpoint:
Hitting a breakpoint will be more helpful than just crashing, since it gives you a chance to inspect the console to get details about the incorrect constraints.

There is no strict mode as such that will do it. Calculating constraints is done at runtime considering the existing device's size, resolution, etc. But you can test your app once in every size class before releasing to production. For example: iphone 5, iphone 6, iphone 10, 8plus.
Also while running the app, check for the logs and search for "NSLayoutConstraint". If there is any constraint failing, you will see those in logs when you search for that string.

Related

How I can manage Adaptive layout via Autolayout

First of all apologize for the article if it is duplicate.
After a lot of boxing with autolayout I don't get result. I am working on a application that manages on both phone and iPad.
As I implemented design with autolayout in iPhone mode with all trait vary versions when trying to make it in iPad. I am getting this locked scenario. Here is screenshot
And this is screenshot for iPhone mode:
I have tried few attempts to correct this but every time I am getting this wierd scenario.
Anyone can suggest me how can I manage this in both device types?

iPhone app is running at iPhone 4 size with black bars after update

Previously the app supported the iPhone 5s/SE screen and iPhone 6-8 screens (not the plus sizes), this was done using launch images. So on Plus sized devices and iPhone X* devices it would display black bars above and below the app.
We then released an update where among other things a launch storyboard was added. All through the development of this update the screen size worked perfectly on every device we had. However after releasing the update on the App Store, for some users, the app now shows at iPhone 4 size (height/width ratio is 1.5). So now affected users on an SE have the black bars, and X* users have bigger black bars the before. This doesn't seem to affect everyone, and we can't replicate on our devices.
The deployment target is 10, so there should be no reason to use the old launch images method. And the update is definitely using a storyboard for the launch screens.
Has a similar thing happened to anyone else? Or is there something you have to do specially when releasing an update that moves to the storyboard method from individual launch images?
All the existing answers either say to make sure you have the correct screenshots, or use a xib/storyboard. We don't have any screenshots and are definitely using a storyboard.
EDIT: now after a few hours of restarting the app users are starting to see the correct sizes, implying it’s an iOS caching issue.
I have experienced it lot before.
Reason: iOS commonly keeps launch screens of all apps in its own cache system, So, unless your app get loaded,it can show that launch images/screen to user from cache. Now, As your app was previously having launch images and now moved to storyboard, it makes this problem.
Also note that, iOS always render your app in screensize which it have in launchscreen, thats why you are seeing black bars at top and bottom.
Way to reproduce: This will happen everytime you update your launch screen. Try adding some label or some other component to your launchscreen.storyboard and install it. You will not see updated launch screen for some duration.
Best Solution(It works almost for all): Just update your app's version number and install on the device. After version number get updated, it will take new updated resources.
If above solution didn't worked for you, then you can try for these alternate solutions:
Solution 01: Your user might have to delete older app and install new one
Solution 02: Your user needed to reboot their device after update.
Solution 03: iOS System itself refreshes its own cache after certain interval, so your customers might face issue just after updating... but will get resolved automatically after some duration(around 3-4 hours).
I experienced similar issues with LaunchScreen Storyboard changes and when switching from Launch Images. It is an iOS Bug, sometimes you need to reboot the device in order to see the correct LaunchScreen when changes are made, it is very odd and difficult to reproduce.
Most probably there is nothing wrong with your App...
Yes Jonathan, it has happened to others as well.
Sadly it seems that this is a real iOS issue, the problem is real (those negationists please believe).
I called the Apple Support and the developer/support staff that I talked with, seemed aware and/or heard the issue, although the response was unclear I did, nonetheless, report the issue properly. "They will check it out". Typical Apple sideways answer...
Now, current solutions:
It seems that what has worked is the On/off iPhone solution, drastic and heavily inconvenient but currently it's the only workaround "tested".
I am deeply sorry for not solving you inquire straight, but I think this affair is beyond any of us developers field of action, it seems (yet to confirm) an OS problem, which Apple and only Apple can fix for real.

How to debug layout constraint issues in iOS?

I'm unable to build an interface I want to build as the objects does not obey the constraints I place on them.
Clarification to this who do not understand the question above:
I want what I see in Xcode on all devices, no matter the constraints on a iPhone 7+ and I assume a 7 and lower the image is either stretched or reshaped.
iphoneX simulator renders correctly
iPhone 7+ with same constraints
Xcode:
Build:
So this is the answer as it's only affecting me currently. It's been escalated to Code-Level Support, They are sending someone to the team to investigate my mac as even when reinstalling Xcode it should not have or build the problem above. If anyone else is having the trouble above they should use a code-level support request as this is on their end as far as we know about.

iPhone Simulator vs. Main Storyboard Preview

I have many layout constraints for a particular app, and in the main.storyboard (preview) the apps look a little bit off, but when I run them in the simulator they look how I want them. So there is disconnect between the two.
I saw the question answered that fixing the constraint warnings would then make the two appear identical.
However, I do not want to try to fix these warnings. A lot of time went into finally figuring how to lay all this out, and I'm worried fixing these (38) constraint errors will screw everything up.
My question is...with the disparity between the preview and the actual device simulation, which one will actually appear if the app is run on a real device? I would assume the one showing in simulation, but I'm really not sure. Is it safe to ignore the errors and the strange main.storyboard (preview) layout it shows me and go with the simulation? It looks how I want it for each simulated device, so I'm weary of changing anything now. Thank you!
According to my experience, Xcode has some problems in storyboard. If you have a constraint which makes a view becomes visually invisible, you will get a warning about this constraint. You can quickly fix it by clicking the warning icon BUT if you close you project and reopen it again, the warning will be there.
The final result should be the UI shown in simulator instead of interface builder or storyboard.

iOS app layout in the simulator different than on the actual device

My app looks completely different on a real device compared to a simulator. I used storyboard and used "add missing constraints" on all objects to remove warnings. Could this have caused the problem?
The actual device has most image views collapsed in the upper left corner
The simulator (for all devices you can test with) shows all 4 images filling the screen
Thanks!
A likely cause would be Autolayout constraints that do not create the intended effect.
You may be seeing the expected behaviour in the simulator simply because it has old cached versions of the NIB files... sometimes will get device/simulator differences due to this. Alternatively, could be the app on the device that has the old version. A clean build may result in problem resolved or seeing the same problem in both places, either of which solves half the question.
Using the automatic "Add missing constraints" is almost certainly the immediate cause here, if the problem occurred at the same time you did that.
Presuming you have the project under source control, I'd recommend rolling back and adding missing constraints in a more planned way, as the automatic system isn't smart enough for every scenario it seems.

Resources