program tip

Xcode 7, iOS 9로 프로젝트를 실행할 때 "애플리케이션 창에 애플리케이션 실행 종료시 루트 뷰 컨트롤러가있을 것으로 예상됩니다."오류

radiobox 2020. 9. 23. 07:29
반응형

Xcode 7, iOS 9로 프로젝트를 실행할 때 "애플리케이션 창에 애플리케이션 실행 종료시 루트 뷰 컨트롤러가있을 것으로 예상됩니다."오류


기능 실행 후

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

충돌이 있습니다.

 Assertion failure in 
-[UIApplication _runWithMainScene:transitionContext:completion:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-

 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', `enter code here`reason: 'Application windows are expected to have a root view controller at the end of application launch'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000109377885 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000108df0df1 objc_exception_throw + 48
    2   CoreFoundation                      0x00000001093776ea +[NSException raise:format:arguments:] + 106
    3   Foundation                          0x0000000108a42bb1 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
    4   UIKit                               0x000000010760e350 -[UIApplication _runWithMainScene:transitionContext:completion:] + 2875
    5   UIKit                               0x000000010760b73f -[UIApplication workspaceDidEndTransaction:] + 188
    6   FrontBoardServices                  0x000000010b87fd7b FrontBoardServices + 163195
    7   FrontBoardServices                  0x000000010b880118 FrontBoardServices + 164120
    8   CoreFoundation                      0x00000001092a20f1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    9   CoreFoundation                      0x0000000109297eac __CFRunLoopDoSources0 + 556
    10  CoreFoundation                      0x0000000109297363 __CFRunLoopRun + 867
    11  CoreFoundation                      0x0000000109296d78 CFRunLoopRunSpecific + 488
    12  UIKit                               0x000000010760b091 -[UIApplication _run] + 402
    13  UIKit                               0x000000010760f79b UIApplicationMain + 171
    14  bbwc                                0x00000001037a9998 main + 344
    15  libdyld.dylib                       0x000000010a45ca05 libdyld.dylib + 10757
    16  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

이 프로젝트는 오래된 프로젝트입니다. Xcode 7 및 iOS 9로 빌드하고 실행하려면 어떻게해야합니까?


오류 메시지에서 :

응용 프로그램 시작이 끝날 때 응용 프로그램 창에 루트보기 컨트롤러가있을 것으로 예상됩니다.

이 "오래된"프로젝트는 몇 살입니까? 몇 년이 지난 경우에도 다음과 같은 정보가 있습니까?

[window addSubview:viewController.view];

대신 다음으로 대체해야합니다.

[window setRootViewController:viewController];

앱 델리게이트에서 self.window의 rootViewController를 이미 설정했는데 런타임에이 오류가 계속 발생하는 경우 UIApplication에 둘 이상의 창이 있고 그중 하나에는 rootViewController가 연결되어 있지 않을 수 있습니다. 앱 창을 반복하고 빈 viewController를 rootViewController에 연결하여 오류를 수정할 수 있습니다.

다음은 앱 창을 반복하고 창이없는 경우 빈 ViewController를 rootViewController에 연결하는 코드입니다.

NSArray *windows = [[UIApplication sharedApplication] windows];
for(UIWindow *window in windows) {
    NSLog(@"window: %@",window.description);
    if(window.rootViewController == nil){
        UIViewController* vc = [[UIViewController alloc]initWithNibName:nil bundle:nil];
        window.rootViewController = vc;
    }
}

업데이트 : 일반적으로이 문제를 일으키는 상태 표시 줄 전용 창이 있습니다. 위의 코드는이 오류를 수정해야합니다.


XCODE 7에서는 모든 Windows에 rootViewController가 있어야합니다. 쉽게 사용할 수 있습니다.

UIViewController* vc = [[UIViewController alloc]initWithNibName:nil bundle:nil];
self.window.rootViewController = vc;

It's working good if you need to use only UIWindow (for easy examples from any Tutorials - before Xcode 7)!


It seems that since iOS 9.1(?) or Xcode 7.1 any UIWindow instantiated during application(_:didFinishLaunchingWithOptions:) needs to have a rootViewController set before leaving that method.

Previously it was sufficient for only the main window to have a rootViewController set during that method. Now any UIWindow instance needs to have a valid rootViewController property.

The culprit here could be your own code if you make use of UIWindow and also any other third party library that tries to initialize a new UIWindow instance during this time (like status bar message overlays, etc.).

NOTE: You also get the same error if you don't set the rootViewControleron your main window or if your storyboard is not set up right. Mentioning this as a side note since those cases are pretty obvious and straightforward to fix.


This has bitten me today too, and it cost me a few hours to fix it: my App has the window in a "MainWindow.xib", complete with navigation controller and accompanying root view controller, that were all automatically instantiated in the proper order, with Xcode 6 and iOS8.

On iOS9 that App still runs fine when downloaded from the AppStore, but not when newly built with Xcode 7 and run on iOS 9. At the time the app delegate is executing its applicationDidBecomeActive: method the root view controller is now not loaded, as it used to be before! That made the root view controller miss the call to my restore state code.

I fixed this by instantiating the root view controller myself, in code, and restoring its state from the viewDidLoad, explicitly.


You should set every window's rootviewcontroller property in your app


Just set your rootViewController to navigationController which is your UIViewController in the app-delegate.rb like my code below. I am new in ruby but hope this helped...

rootViewController = UIViewController.alloc.init

@window.rootViewController = navigationController

I came into this issue with an app I more ore less inherited. After verifying that the storyboard was properly set up as the apps main interface and that the storyboard had a RootViewController I was still getting the crash.

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Application windows are expected to have a root view controller at the end of application launch'

What I discovered after some further investigation that the crash was being caused by some view logic (SVProgressHud) being called in - (void)applicationDidBecomeActive:(UIApplication *)application. This seems to be new behavior in Xcode7 but as far as I can tell SVProgressHud was referencing the rootviewcontroller before it was set by the storyboard. Ultimately updating SVProgressHud to 2.0 fixed the bug.


I have an older project that worked in iOS 8 but not iOS 9. If your Main Interface is set to MainWindow.xib, update it to a storyboard. This fixed it for me:

  1. Create a new project, Single View Application is fine.
  2. Copy the Main.storyboard file to your project, or you could just create your own.
  3. Open your Project Settings and Set your Main Interface to Main.storyboard Set your Main Interface to Main.storyboard

Swift 2 solution that worked for me :

Insert the code below in AppDelegate -> didFinishLaunchingWithOptions

self.window!.rootViewController = storyboard.instantiateViewControllerWithIdentifier("YourRootViewController") as? YourRootViewControllerClass

참고URL : https://stackoverflow.com/questions/30884896/application-windows-are-expected-to-have-a-root-view-controller-at-the-end-of-a

반응형