我见过很多iPhone应用在iPad上运行,按键名为x1
和x2
。我有一个应用程序,首先我将其作为universal
应用程序开发,但现在我将其更改为iPhone
并希望在iPad上使用x1
和x2
样式运行它当我在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
它在iPhone上正常工作,但我在iPad上看到了这个崩溃?
我在didFinishLaunchingWithOptions中有这个代码来初始化核心数据
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//--------- Initialize appearance and database ------------//
[[BRCoreRepository instance] initializeDatabase:self.managedObjectContext];
// Othe ui codes is here
return YES;
}
在iPad版本中,didFinishLaunchingWithOptions
没有调用,因此应用程序不会通过核心数据的初始化阶段,而在显示viewController之前它会崩溃。
请注意,它在iPhone中运行良好,iPad中存在问题
这是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
)
我想知道didFinishLaunchingWithOptions
是如何调用的,但视图会显示出来。初始化核心数据和初始化方法的最佳位置在哪里,不要面对这个问题?
答案 0 :(得分:0)
最后我发现这是因为UIFont+SystemFontOverride
类。
我使用此类来覆盖我的应用程序的系统字体:
#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
似乎当我们使用带有ZoomViewController
的iPad时,该方法会在didFinishLaunchingWithOptions
之前调用,问题在于boldSystemFontOfSize
和systemFontOfSize
的实现我使用了正在didFinishLaunchingWithOptions