簡體   English   中英

didFinishLaunchingWithOptions未調用,但應用程序正在運行並面臨崩潰

[英]didFinishLaunchingWithOptions not called but app is running and faced with crash

我見過很多在iPad上運行的iPhone應用程序,它們的按鈕名為x1x2 我有一個應用程序,首先我將其開發為universal應用程序,但現在我將其更改為iPhone並希望以x1x2樣式在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

它可以在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是否有可能不調用但視圖將顯示。 哪里是初始化核心數據和初始化方法的最佳位置而不會遇到此問題?

最終我發現這是因為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

它似乎是,當我們使用與iPad ZoomViewController的方法之前調用didFinishLaunchingWithOptions ,問題是,在實施boldSystemFontOfSizesystemFontOfSize我使用的是在初始化庫didFinishLaunchingWithOptions

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM