problem with new app for ipad 12.9 in 2nd gen

Discussion in 'iOS Programming' started by theprizerevealed, Feb 4, 2018.

  1. theprizerevealed macrumors member

    Joined:
    Feb 26, 2016
    #1
    I'm coding a new app and I'm experiencing a problem with making it work for the second generation 12.9 inch ipad. The uiview does not appear where it should in one of the view controllers and the segue to the next view controller causes the app to crash.

    However, these problems do not appear in any other ipad version nor for the iphone or ipod while simulating the app.

    There are some warning messages too about fixed width constraints, which I'm not sure how to address properly.

    Can anyone suggest the cause of these issues? thanks for your ideas.
     
  2. PhoneyDeveloper macrumors 68040

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    What do you mean crash? Is there a crashlog that you can post? Is there a stack trace in the debugger? What are the warnings?
     
  3. theprizerevealed thread starter macrumors member

    Joined:
    Feb 26, 2016
    #3
    Code:
    [LayoutConstraints] 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:0x60c0000986a0 UIView:0x7fa556d0c040.width == 375   (active)>",
        "<NSLayoutConstraint:0x60c0000990a0 UIView:0x7fa556d0c040.leading == UILayoutGuide:0x60c0005bcd20'UIViewSafeAreaLayoutGuide'.leading   (active)>",
        "<NSLayoutConstraint:0x60c0000990f0 UIView:0x7fa556d0c040.trailing == UILayoutGuide:0x60c0005bcd20'UIViewSafeAreaLayoutGuide'.trailing   (active)>",
        "<NSLayoutConstraint:0x608000099960 'UIView-Encapsulated-Layout-Width' UIView:0x7fa556d06250.width == 1024   (active)>",
        "<NSLayoutConstraint:0x60c000098bf0 'UIViewSafeAreaLayoutGuide-left' H:|-(0)-[UILayoutGuide:0x60c0005bcd20'UIViewSafeAreaLayoutGuide'](LTR)   (active, names: '|':UIView:0x7fa556d06250 )>",
        "<NSLayoutConstraint:0x60c000098c90 'UIViewSafeAreaLayoutGuide-right' H:[UILayoutGuide:0x60c0005bcd20'UIViewSafeAreaLayoutGuide']-(0)-|(LTR)   (active, names: '|':UIView:0x7fa556d06250 )>"
    )
    
    Will attempt to recover by breaking constraint
    <NSLayoutConstraint:0x60c0000986a0 UIView:0x7fa556d0c040.width == 375   (active)>
    
    Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
    The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
    2018-02-08 01:23:11.354348-0500 Photorespiration Tutor[13830:2929430] [LayoutConstraints] 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:0x60c000098a10 UILabel:0x7fa556d0c720'Identify This Structure:'.width == 375   (active)>",
        "<NSLayoutConstraint:0x60c000099190 UILabel:0x7fa556d0c720'Identify This Structure:'.leading == UILayoutGuide:0x60c0005bcd20'UIViewSafeAreaLayoutGuide'.leading   (active)>",
        "<NSLayoutConstraint:0x60c0000991e0 UILabel:0x7fa556d0c720'Identify This Structure:'.trailing == UILayoutGuide:0x60c0005bcd20'UIViewSafeAreaLayoutGuide'.trailing   (active)>",
        "<NSLayoutConstraint:0x608000099960 'UIView-Encapsulated-Layout-Width' UIView:0x7fa556d06250.width == 1024   (active)>",
        "<NSLayoutConstraint:0x60c000098bf0 'UIViewSafeAreaLayoutGuide-left' H:|-(0)-[UILayoutGuide:0x60c0005bcd20'UIViewSafeAreaLayoutGuide'](LTR)   (active, names: '|':UIView:0x7fa556d06250 )>",
        "<NSLayoutConstraint:0x60c000098c90 'UIViewSafeAreaLayoutGuide-right' H:[UILayoutGuide:0x60c0005bcd20'UIViewSafeAreaLayoutGuide']-(0)-|(LTR)   (active, names: '|':UIView:0x7fa556d06250 )>"
    
    Is this the kind of thing you're talking about? The issue relates to some pictures that I want to display in my app. The pictures have certain dimensions of course, so I'm wondering if that might be a cause. However the pictures display fine in the first generation ipad 12.9 inch so I'm wondering why the second generation is a problem...
     
  4. PhoneyDeveloper macrumors 68040

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    Those are constraint warnings. They don't usually cause a crash but they're probably the reason your label is in the wrong place or is the wrong width. I think both warnings are the same.

    I think the width, leading and trailing were created by you. The others were created by UIKit. The warnings say that the width = 375 conflicts with the width = 1024 and it helpfully broke the one you set and used the one UIKit set.

    Anyway, you've told the label to be as wide as the screen by setting the leading and trailing to the safe area. But you also have a width of 375. On an iPad the width of the safe area is going to be wider than that. 1024 is the width of an iPad in landscape. So that's your conflict. If you want the label to be as wide as the screen then remove the width = 375 constraint and that will probably fix things. If you really want it to be only 375 wide you'll have to adjust the leading and trailing constraints.

    BTW, I don't think a misplaced label like this could cause a crash. You'll need to post a crashlog for us to help with that.
     
  5. theprizerevealed thread starter macrumors member

    Joined:
    Feb 26, 2016
    #5
    thanks, I'll try to adjust it. As for what else might cause the crash, there is something in what I think is the crash log that says unwrapping an optional value on an item in an array was found to be nil. However, again why would this be peculiar to only the 2nd generation ipad 12.9 inch? I hate to post the crash log because it reveals some details about the nature of my app. I don' think there are any competitors to it, but all the same I wish to try to keep it private until it is released.
     
  6. PhoneyDeveloper macrumors 68040

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    You don't give enough info to answer why this bug is only revealed on a particular device. The crashlog should help to identify the exact line that the crash occurs on. Usually you can also discover this by running the app in the debugger.

    Unexpected nil when unwrapping an optional suggests you used force unwrapping, which is a bad practice in many cases.

    Maybe something about the screen size is what you're running into. Really, trying to guess the answer to why it crashes on this device only probably isn't productive. Instead you should debug it and learn what the cause is. If it crashes every time or you know what the conditions are to cause it you should be able to figure it out.
     
  7. theprizerevealed thread starter macrumors member

    Joined:
    Feb 26, 2016
    #7
    Perhaps it is related to the forced unwrapping, Xcode shows me the line of code where there is a problem and the general code I use is something near this:

    Code:
     var ArrayofImages:[UIImage] = [UIImage(named: "PictureOne")!, UIImage(named: "PictureTwo")!] 
    I can try making new pictures with dimensions nearer to the shape of the UIVEW but I'm wondering too if there is anything about Assets.xcassets that I'm missing?
     
  8. PhoneyDeveloper macrumors 68040

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #8
    You should step over that line in the debugger to see if it crashes. Or put some print statements around it to see if it succeeds or fails. It shouldn't be a question of Perhaps.

    Using forced unwrapping in this case is generally OK in my book. You can verify that it works and it's like an assertion that the image exists.
     
  9. theprizerevealed thread starter macrumors member

    Joined:
    Feb 26, 2016
    #9
    What's the easiest way to say the constraints for images, labels, uiviews and such so that the distances among them will be the same proportionally among all the different device types?
     
  10. theprizerevealed thread starter macrumors member

    Joined:
    Feb 26, 2016
    #10
    The array is such a key part of the program that I don't know how to skip over it without causing numerous other problems in the viewcontroller. There is a message about lldb but I don't know how to use it to identify the problem.

    At least I solved the constraints issue by learning to use the autosizing of constraints in the Size Inspector.

    One other thing, without changing the dimensions the pictures to be displayed in the Assets.xassets, I did change a characteristic of the pictures to Generic RBG after reading some posts on the net. However this made no difference.

    What in the world could be different about the second generation ipad to cause such behavior?
     
  11. PhoneyDeveloper macrumors 68040

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #11
    When you say "I don't know how to skip over it" are you referring to where I said "You should step over that line in the debugger to see if it crashes"? I mean "step over" as in "single step" in the debugger. You set a breakpoint on that line or a line before it. Then run the app until it stops in the debugger on that line. Then click the single step button in the debugger for each line. Step Step Step. Until you get to the line that you suspect is a problem. View the local variables. This is how you figure out what's going wrong.
     
  12. theprizerevealed, Feb 25, 2018
    Last edited: Feb 25, 2018

    theprizerevealed thread starter macrumors member

    Joined:
    Feb 26, 2016
    #12
    Let me try another way to frame the question. The optional unwrapping issue seems to refer to the name of the image file. The first generation ipad executes the same code with no problem and you can see the image just fine in the uiview.

    There is something about ipad 2nd generation that cannot unwrap the optional for the image file name.

    What could be the cause of that? The particular line of code seems to work fine in all other devices.

    Just to be sure I check the autoresizing and it works fine on the uiview to adjust the size of the uiview appropriately.

    EDIT: Okay while using breakpoints it appears that the name of the file is passed to the uiview to display the image because I can see the name of the image file in the (is it the debugger window on the bottom left of xcode?). So a image file name is being passed. Something else is preventing the image from being shown in the uiview....
     
  13. PhoneyDeveloper macrumors 68040

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #13
    Some of the differences between various devices are 32-bit/64-bit, the OS version, retina screen, triple pixels on plus phones, screen height and width and probably some others. I don't know what might make an image available on one but not another.

    Sometimes when debugging you need to break it down to smaller and smaller bits of code. In your case I would write a few lines like

    let image1 = UIImage(named: "PictureOne")!

    for each of the images. Set a breakpoint on the first line. Step over it and view the value of each of the variables to see if they are valid. Because of the force unwrapping I think it will crash on one of those lines if the image can't be loaded. If they are all valid then this isn't the place in your code that is failing. You would need to post here a crashlog to get better feedback.
     
  14. theprizerevealed, Mar 12, 2018
    Last edited: Mar 12, 2018

    theprizerevealed thread starter macrumors member

    Joined:
    Feb 26, 2016
    #14
    Okay, I seem to have solved this issue at least cursorily, by using jpeg images instead of png. The image file displays now in the ipad second generation. My question now becomes, which type of software should I use to capture images that have an acceptable resolution while maintaining low files sizes? Which file type for an image should I use for these criteria? Does any software come with macOS to do this? thanks
     
  15. theprizerevealed thread starter macrumors member

    Joined:
    Feb 26, 2016
    #15
    Arg! It vexes me yet! I'm ready almost to submit but it won't accept my screenshots for the ipad 12.9 inch! Why oh why!?! Fixing the image issue by using .jpg files seems to work okay - it displays properly. So why won't it accept screenshots from the simulator?! Help!
     
  16. TheWatchfulOne macrumors 6502

    TheWatchfulOne

    Joined:
    Jun 19, 2009
    #16
    Are the screenshots from the simulator the right pixel dimensions for the device you are simulating? The simulator size is adjustable. My experience has been that if I size the iPad simulator down so I can see all of it, and then take a screenshot, the image pixel dimensions will be smaller than they should be. But if I only downsize the simulator to pose my shot, and then change the simulator size to full size before saving the screenshot, the image dimensions will be correct.
     
  17. theprizerevealed thread starter macrumors member

    Joined:
    Feb 26, 2016
    #17

Share This Page