Search code examples
iosobjective-ciphonexibios10

iOS 10: Fatal Exception: NSInternalInconsistencyException Could not load NIB in bundle


Crash reported on App store app with the exception:

`NSInternalInconsistencyException Could not load NIB in bundle...`

This crash is being reported since the last two months on iOS 10 devices and for multiple xib files.

Details of one such instance:

Fatal Exception: NSInternalInconsistencyException
Could not load NIB in bundle: 'NSBundle </var/containers/Bundle/Application/XXX/MyApp.app> (loaded)' with name 'VideoView'`

Fatal Exception: NSInternalInconsistencyException
0  CoreFoundation                 0x18d7551b8 __exceptionPreprocess
1  libobjc.A.dylib                0x18c18c55c objc_exception_throw
2  CoreFoundation                 0x18d755100 -[NSException initWithCoder:]
3  UIKit                          0x193b04fcc -[UINib instantiateWithOwner:options:]
4  UIKit                          0x193965e14 -[UIViewController _loadViewFromNibNamed:bundle:]
5  UIKit                          0x193737980 -[UIViewController loadView]
6  UIKit                          0x1936035bc -[UIViewController loadViewIfRequired]
7  UIKit                          0x1936034ec -[UIViewController view]
8  MyApp                        0x100135580 -[VideoEventController addMediaPlaybackViewForChannel:andProgram:ofType:] (VideoEventController.m:113)

Code used to init view controller is:

self.videoViewCtrl = [[VideoViewController alloc] initWithNibName:@"VideoView" bundle:nil];
[mediaView addSubview:self.videoViewCtrl.view]; //Crash trace points to this line in code

Checklist:

  1. Issue is not always reproducible for particular xib and hence no reference mistake or No spelling mistakes in xib name
  2. xib files are present in Copy Bundle Resources
  3. xib files are linked to target in Target Membership
  4. Location of xib files set to Related to Group

Code uses AutoLayout but not the size classes. Project has separate xibs for iPad and iPhone adhering to naming conventions.

Did anyone face the same issue? What could be the reason for failure to load NIB?


Solution

  • After months of investigation finally we figured out what was causing the issue.

    We have one static library (in-house) integrated with app for analytics purposes. We found that, this library is leaking the file descriptors acquired for i/o operations.

    What happens is, as soon as app runs out of the i/o resources, the very next resource request fails. In our case its the xib initialisation. This error was causing the app to crash with exception:

    `NSInternalInconsistencyException Could not load NIB in bundle.`
    

    Below references actually helped us to draw this conclusion.

    1. On iOS 10, NSFetchedResultsController leaks 'open file descriptors'
    2. socketpair failed 24 (too many open files)

    How we zeroed on library is:

    1. We never observed the issue in debug build and in production it was consistently reproducible
    2. One of the major difference in debug build and production build was, the analytics library is disabled in debug
    3. We could reproduce the issue on debug build with analytics library enabled

    We have reported our observations to library dev team and awaiting the response.