[英]didFinishLaunchingWithOptions not called but app is running and faced with crash
I had seen lots of iPhone apps that running on iPad with buttons name x1
and x2
. 我见过很多在iPad上运行的iPhone应用程序,它们的按钮名为
x1
和x2
。 I have an application that first I developed it as a universal
app but now I changed it to iPhone
and expect to run it on iPad with that x1
and x2
style but when I run it on the iPad I see this core data error: 我有一个应用程序,首先我将其开发为
universal
应用程序,但现在我将其更改为iPhone
并希望以x1
和x2
样式在iPad上运行,但是当我在iPad上运行时,我看到此核心数据错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'Settings''
*** First throw call stack:
(0x187b6659c 0x1987cc0e4 0x18781d278 0x100110984 0x100110ab8 0x100110494 0x1000f4cdc 0x1000d2644 0x1000d2720 0x18c835544 0x18c318844 0x18c3187b0 0x18c834fbc 0x18c832ce8 0x18c344788 0x18c5af238 0x18c5aecec 0x18c5aec44 0x18c5a2578 0x18c5a1fe0 0x18fdb1edc 0x18fdc162c 0x187b1ea28 0x187b1db30 0x187b1c154 0x187a490a4 0x18c3833c8 0x18c37e3c0 0x100108098 0x198e3aa08)
libc++abi.dylib: terminating with uncaught exception of type NSException
It is working right on iPhone but I see this crash in iPad? 它可以在iPhone上正常运行,但我在iPad上看到此崩溃?
I have this code in my didFinishLaunchingWithOptions that initialize core data 我的didFinishLaunchingWithOptions中有此代码,用于初始化核心数据
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//--------- Initialize appearance and database ------------//
[[BRCoreRepository instance] initializeDatabase:self.managedObjectContext];
// Othe ui codes is here
return YES;
}
In iPad version the didFinishLaunchingWithOptions
it is not calling so the app do not pass the initialize phase of core data and the before showing the viewController it crashes. 在iPad版本中,
didFinishLaunchingWithOptions
并未调用,因此该应用程序不会传递核心数据的初始化阶段,并且不会显示崩溃的viewController。
Please notice that it is working perfect in iPhone and the problem exist in iPad 请注意,它在iPhone上运行完美,在iPad中存在问题
This is the stack trace in iPad simulator: 这是iPad模拟器中的堆栈跟踪:
*** First throw call stack:
(
0 CoreFoundation 0x000000010d11dd85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010c280deb objc_exception_throw + 48
2 CoreData 0x000000010cc6448b +[NSEntityDescription entityForName:inManagedObjectContext:] + 251
3 APMB 0x000000010bb8f0e4 -[BRSettingsRepository getAllRowsInSettings] + 100
4 APMB 0x000000010bb8f24b -[BRSettingsRepository loadDataFromDB] + 43
5 APMB 0x000000010bb8ec3c +[BRSettingsRepository instance] + 332
6 APMB 0x000000010bb7333e -[BRLanguageManager language] + 46
7 APMB 0x000000010bb4e084 brAppFontWithSize + 68
8 APMB 0x000000010bb4e145 +[UIFont(SystemFontOverride) systemFontOfSize:] + 37
9 UIKit 0x000000010e5e031d -[UIZoomViewController loadView] + 86
10 UIKit 0x000000010e191560 -[UIViewController loadViewIfRequired] + 138
11 UIKit 0x000000010e191cd3 -[UIViewController view] + 27
12 UIKit 0x000000010e5dfcd0 -[UIZoomViewController init] + 82
13 UIKit 0x000000010e5dd85e -[UIClassicController _setupWindow] + 582
14 UIKit 0x000000010e5dd52b +[UIClassicController sharedClassicController] + 246
15 UIKit 0x000000010e0162b5 -[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:] + 557
16 UIKit 0x000000010e015dde -[UIApplication _handleApplicationLifecycleEventWithScene:transitionContext:completion:] + 508
17 UIKit 0x000000010dff48a0 __70-[UIApplication scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke + 159
18 UIKit 0x000000010dff452d -[UIApplication scene:didUpdateWithDiff:transitionContext:completion:] + 843
19 UIKit 0x000000010dff2bca -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 591
20 FrontBoardServices 0x00000001123d32af __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 265
21 FrontBoardServices 0x00000001123eb8c8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
22 FrontBoardServices 0x00000001123eb741 -[FBSSerialQueue _performNext] + 178
23 FrontBoardServices 0x00000001123ebaca -[FBSSerialQueue _performNextFromRunLoopSource] + 45
24 CoreFoundation 0x000000010d043301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
25 CoreFoundation 0x000000010d03922c __CFRunLoopDoSources0 + 556
26 CoreFoundation 0x000000010d0386e3 __CFRunLoopRun + 867
27 CoreFoundation 0x000000010d0380f8 CFRunLoopRunSpecific + 488
28 UIKit 0x000000010dff1f21 -[UIApplication _run] + 402
29 UIKit 0x000000010dff6f09 UIApplicationMain + 171
30 APMB 0x000000010bb86e2f main + 111
31 libdyld.dylib 0x00000001108b592d start + 1
32 ??? 0x0000000000000001 0x0 + 1
)
I am wondering how it is possible that didFinishLaunchingWithOptions
is not calling but the view is going to show. 我想知道
didFinishLaunchingWithOptions
是否有可能不调用但视图将显示。 And where is the best place to initialize the core data and initialize methods to do not face this problems?? 哪里是初始化核心数据和初始化方法的最佳位置而不会遇到此问题?
Finally I found that it is because of UIFont+SystemFontOverride
class. 最终我发现这是因为
UIFont+SystemFontOverride
类。
I use this class to override system font of my application: 我使用此类重写应用程序的系统字体:
#import "UIFont+SystemFontOverride.h"
@implementation UIFont (SystemFontOverride)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
+ (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize {
//return My Custom Bold Font;
}
+ (UIFont *)systemFontOfSize:(CGFloat)fontSize {
//return My Custom Normal Font;
}
#pragma clang diagnostic pop
@end
it seem that when we are using iPad with ZoomViewController
the method are calling before didFinishLaunchingWithOptions
and the problem was that In implementation of boldSystemFontOfSize
and systemFontOfSize
I was using a repository that is initializing at didFinishLaunchingWithOptions
它似乎是,当我们使用与iPad
ZoomViewController
的方法之前调用didFinishLaunchingWithOptions
,问题是,在实施boldSystemFontOfSize
和systemFontOfSize
我使用的是在初始化库didFinishLaunchingWithOptions
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.