简体   繁体   中英

My App crash on iPad before even application:didFinishLaunchingWithOptions:

My app is crashing with the following crashlog when ran on ipad. It just work fine on iphone devices. As you might notice, it crash while trying to setup the window. I have searched everywhere but don't see such an issue in any other topic.

Thanks for you help.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: NSParagraphStyle)'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010e38ff35 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010e028bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010e296998 -[__NSDictionaryM setObject:forKey:] + 968
    3   UIKit                               0x000000010ca99d2d -[UILabel _setLineBreakMode:] + 529
    4   UIKit                               0x000000010cb7a572 -[UIButtonLabel setLineBreakMode:] + 93
    5   UIKit                               0x000000010cb86e5c -[UIButton _setupTitleViewRequestingLayout:] + 308
    6   UIKit                               0x000000010cb7ed15 -[UIButton titleLabel] + 51
    7   UIKit                               0x000000010cd3c6d8 -[UIZoomViewController loadView] + 476
    8   UIKit                               0x000000010c9f67f9 -[UIViewController loadViewIfRequired] + 75
    9   UIKit                               0x000000010c9f6c8e -[UIViewController view] + 27
    10  UIKit                               0x000000010cd3bfa4 -[UIZoomViewController init] + 78
    11  UIKit                               0x000000010cd39eeb -[UIClassicController _setupWindow] + 544
    12  UIKit                               0x000000010cd39b7c +[UIClassicController sharedClassicController] + 140
    13  UIKit                               0x000000010c8e47dd -[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:] + 666
    14  UIKit                               0x000000010c8e42ae __88-[UIApplication _handleApplicationLifecycleEventWithScene:transitionContext:completion:]_block_invoke + 138
    15  UIKit                               0x000000010c8e4215 -[UIApplication _handleApplicationLifecycleEventWithScene:transitionContext:completion:] + 349
    16  UIKit                               0x000000010c8cf31a -[UIApplication scene:didUpdateWithDiff:transitionContext:completion:] + 486
    17  UIKit                               0x000000010c8cedb8 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 336
    18  FrontBoardServices                  0x000000011064f612 __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 265
    19  FrontBoardServices                  0x000000011065e2a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
    20  CoreFoundation                      0x000000010e2c553c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    21  CoreFoundation                      0x000000010e2bb285 __CFRunLoopDoBlocks + 341
    22  CoreFoundation                      0x000000010e2bb045 __CFRunLoopRun + 2389
    23  CoreFoundation                      0x000000010e2ba486 CFRunLoopRunSpecific + 470
    24  UIKit                               0x000000010c8ce669 -[UIApplication _run] + 413
    25  UIKit                               0x000000010c8d1420 UIApplicationMain + 1282
    26  Edyn                                0x0000000109704323 main + 115
    27  libdyld.dylib                       0x000000010ebd2145 start + 1
    28  ???                                 0x0000000000000001 0x0 + 1
)

Edit 1

The problem is more complicated than I thought. Here is what I have done.

  1. Implemented method swizzling around [UIButtonLabel setLineBreakMode:] so that I can see what is causing to use nil for the LineBreakMode. I found out that if lineBreakMode is set to something else than NSLineBreakByWordWrapping it ultimately crash.
  2. To temporary make it work I am forcing the lineBreakMode to NSLineBreakByWordWrapping which is not a big deal in this case because the label is never seens in my app.

Edit 2

After fixing the issue with lineBreakMode , I am now getting the same issue but this time with [UILabel setShadow:]. Note that it crash on label where I didn't change anything to the shadow attributes (color, offset or blurRadius). I also get the same issue but this time with paragraphStyle

Which mean I can't definitely not keep using this approach as it seems to be something broken in what's happening.

Edit 3

When I change the deployment target of my app to universal, I don't have any of the above issues.

I was overriding those two functions in a category and guess what? those function seems to be called by ios even before you get control of the app in your AppDelegate. And for some reason on ipad this return nil. Removing the category fixed the problem.

+ (id)systemFontOfSize:(CGFloat)sz {
    return [UIFont fontWithName:@"HelveticaNeue-Regular" size:sz];
}
+ (id)boldSystemFontOfSize:(CGFloat)sz {
    return [UIFont fontWithName:@"HelveticaNeue-Bold" size:sz];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM