在应用程序之前,我的应用程序在iPad上崩溃:didFinishLaunchingWithOptions: [英] My App crash on iPad before even application:didFinishLaunchingWithOptions:

查看:733
本文介绍了在应用程序之前,我的应用程序在iPad上崩溃:didFinishLaunchingWithOptions:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ipad上运行时,我的应用程序崩溃了以下崩溃日志。
它在iphone设备上运行正常。
您可能会注意到,它在尝试设置窗口时崩溃了。我到处搜索,但在任何其他主题中都没有看到这样的问题。

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.

感谢您的帮助。

*** 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
)

编辑1

问题比我想象的要复杂得多。这就是我所做的。

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


  1. 实施的方法在 [UIButtonLabel setLineBreakMode:] 周围徘徊,以便我可以看到是什么导致使用nil为LineBreakMode。我发现如果将 lineBreakMode 设置为 NSLineBreakByWordWrapping 以外的其他东西,它最终会崩溃。

  2. 暂时让它工作我强迫lineBreakMode到 NSLineBreakByWordWrapping 在这种情况下这不是什么大问题,因为我的应用程序中的标签永远不会被查看。

  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.

修改2

使用 lineBreakMode 解决问题后,我现在遇到同样的问题,但是这个时间[UILabel setShadow:]。
请注意,它在标签上崩溃,我没有更改任何阴影属性(颜色,偏移或blurRadius)。
我也得到了相同的问题,但这一次是用 paragraphStyle

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.

编辑3

我将我的应用程序的部署目标更改为通用,我没有上述任何问题。

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

推荐答案

我压倒一切这两个功能在一个类别中猜猜是什么?即使在你的AppDelegate中控制应用程序之前,这些功能似乎也被ios调用。由于某种原因,在ipad上这个回报为零。
删除类别修复了问题。

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];
}

这篇关于在应用程序之前,我的应用程序在iPad上崩溃:didFinishLaunchingWithOptions:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆