Could not locate an NSManagedObjectModel for entity name - Universal App - iphone

I have a strange error in my app, which says:
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Book'
I know, there are hundrets of "Could not locate an NSManagedObjectModel for entity name" topis here and on the web, but the strange thing is, it's a universal app and the iphone app always works fine, only the ipad app is crashing on startup.
In the main AppDelegate, there is some code in two methodes and in the iphone / ipad AppDelegate I'm calling this code in applicationdidFinishLaunchingWithOptions like this:
if ([self modelExists] == NO) {
[self buildModel];
}
So it's the same way I call the code, but the ipad version crashes and the iphone version does not.
The only different is that the iPhone version uses a TabBarContoller (set up in IB) and the iPad version uses a single viewController (also set up in IB).
It happens on both, simulator and device.
I have no idea what to do. Hope you can understand what I mean ...
Thx a lot
Sebastian
EDIT:
I found out, when I run the iPhone Version, the code in the main AppDelegate is called as it should be, but when I run the iPad Version NONE code of the main appDelegate is called at all, so there is no managedObject created and that's the reason for the error. But why is no code run in the main AppDelegate ? Thx
EDIT2:
This is the code in my main AppDelegate now:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([self modelExists] == NO) { // Checks if the model is allready filled up or not. (Uses CoreData stuff of course)
// iPhone Version is fine here. iPad Version crashes.
[self buildModel];
}
[self buildInterface]; // Called in the iPhone or iPad AppDelegate to make the window visible etc.
return YES;
}
So didFinishLaunchingWithOptions is called in the iphone and in the ipad version. The iPad version just doesn't run the coredata stuff anyway, whereas the iphone version does run the coredata stuff as it should. Any idea what could be wrong? THX!

Maybe the app delegate is not running any code if it's just not set as an delegate of the application.
Look in your main NIB for the iPad version and make sure the "AppName App Delegate" is set as the delegate of the File's owner of that NIB.

I found my problem. Really strange ...
It was the code of "modelExists"
- (BOOL)modelExists {
NSFetchRequest *request = [[NSFetchRequest alloc] init];
request.entity = [NSEntityDescription entityForName:#"Book" inManagedObjectContext:__managedObjectContext]; //<- Crashed. Had to change it to self.managedObjectContext
request.predicate = nil;
NSError *error = nil;
...
Sebastian

I had this same problem. My app had been working fine for weeks in development, then suddenly it was crashing with this error. Changing managedObjContect to [self managedObjectContext] solved the problem.
I would love to know why....any experts out there? Why would the original code be able to resolve the call to managedObjectContext to the member function's implementation....and suddenly not be able to? There is no other static implementation visible to this code as far as I know.
Thank for posting this, save me many hours of messing around.

In my project, I had a navigation controller and I was getting this error when I tried to segue into a child view control.
The problem was that I needed to pass set the managedObjectContext. This is taken from the CoreDate Master/Detail example.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
[[segue destinationViewController] setDetailItem:object];
// set the managedObjectContext, too, if you need it
[[segue destinationViewController] setManagedObjectContext:self.managedObjectContext];
}
}
Also, double check the segue identifier in Interface Builder matches what you have in this function (showDetail in this example).

Related

UIKit NIB not loading in bundle

NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/quantum/Library/Application Support/iPhone Simulator/6.1/Applications/19503C82-22E2-4787-A4F5-8D83EDD5D58B/foo.app> (loaded)' with name '_UIDocumentActivityViewController''
I'm creating a QLPreviewController, presenting it to show a PDF. I then tap the share button. It crashes.
I downloaded Apple's Document Interaction example project. I put my PDF fetching class into there, fetched a PDF, display it.. and it works. No crash on the share button. Both are for targets 6.1. I tried setting Apple's code to target iPad only like my project. Their code works, mine doesn't, and I'm baffled. From the error message it sounds like a bug in the SDK but I can't pinpoint it.
Have you seen this before?
QLPreviewController *previewController = [[QLPreviewController alloc] init];
[previewController setDataSource:self];
[previewController setDelegate:self];
[self presentViewController:previewController animated:YES completion:^{}];
#pragma mark QLPreviewControllerDataSource
- (NSInteger) numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
return 1;
}
- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index {
return [NSURL fileURLWithPath:self.pdfPath];
}
I tried removing the reference to the framework, deleting derived data, cleaning the project, readding the QuickLook framework. I did show in Finder in both Apple's project & mine & they have the same path.
And same thing occurs when I use a UIDocumentInteractionController.
That little overlay with the email/print etc options is not loading in my project.
Apple support provided me with the answer.
I had over ridden an init method in a category and this screwed up the class initialization.
Moral: don't override init in a category method.
just try for initwithnib
QLPreviewController *previewController = [[QLPreviewController alloc] initWithNib: (QLPreviewController) bundle : nil];
hopefully it works.
if you have used NavigationController then use:
QLPreviewController *previewController = [[QLPreviewController alloc] init];
[self.navigationController pushViewController:previewController animated:YES];
else
QLPreviewController *previewController = [[QLPreviewController alloc] init];
[self presentModalViewController:previewController animated:YES];
According to Apple's documentation QL generators should not have NIB files as resources.
Although a Quick Look generator does not (and should not) have nib files as resources, you can add other resources if necessary.

ViewDidAppear crashes on iOS 5.0 simulator

The following code works fine from iOS 3.0 to iOS 4.3 simulator but crashes on iOS5
-(void)viewWillAppear:(BOOL)animated {
[self.tableView reloadData];
[super viewWillAppear:animated];
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.navigationController viewDidAppear:animate];
}
I got exc_bad_access in [self.navigationController viewDidAppear:animate] and it makes the app crashes.
It works fine without any problem in the previous verison.
This app is developed in XCode4 with deployment target 3.0. My user just found the app crashes when he upgraded his iPhone with iOS5.
I am being able to reproduce theproblem but not sure how to fix it.
Can anybody shed some light?
[self.navigationController viewDidAppear:animate]; is the problem here. In iOS 5 it's going to recursively call this view controller's viewDidAppear method over and over until it just crashes. Why exactly do you need to call viewDidAppear manually on your navigation controller? If it's actually necessary to get your code working, you might want to backtrack a bit as something else must be wrong if you're needing to do this.
One other thing that's just good housekeeping: in your viewWillAppear, [super viewWillAppear:animated]; should come first it that method.

What does "WARNING: Input manager failed to load static dictionary for: nl_NL" mean?

I've been working on a dutch localization of a xib file. When I run my app in the simulator, I get the following message in the log console:
WARNING: Input manager failed to load static dictionary for: nl_NL
I've tried to reset the simulator, I've deleted the app, I removed the localization stuff and added it again, I've cleaned my project, but nothing seems to work. I keep getting this warning message.
My questions:
- can I ignore it?
- how can I get rid of this warning?
I've searched the web, but can't seem to find any answer.
If it happens only in the simulator and doesn't cause any other issues, I wouldn't worry too much about it. I just saw this warning for the first time today too.
Some follow-up questions may help:
Which SDK are you using?
Does it happen if you create a new Xcode project from a template?
Is your app still loading the localized nib correctly?
I get the same message when I localise to Spanish (es_ES), but not when I localise to Japanese and to Simplified Chinese (or English for that matter).
I haven't been able to trace the cause or fix this. However in my case this is definitely not the localised xib files, but it arises when I call:
- (NSString *)language {
NSSet *supported_languages = [NSSet setWithObjects: #"en", #"es", #"ja",
#"zh-Hans", nil];
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
NSArray *languages = [defs objectForKey:#"AppleLanguages"];
NSString *primary_language = [languages objectAtIndex:0];
if ([supported_languages containsObject:primary_language]) {
return primary_language;
}
return #"en";
}
But this is only in the simulator.
On the device it works just fine as far as I can tell and I'm ignoring it.
I'm using the 4.2 SDK. I've created the project from a template. It's still loading the localized nib correctly.
What I did find out was the following: it seems to happen only if I run the following code in the didFinishLaunchingWithOptions selector inside the AppDelegate.m file:
AboutViewController *controller = [[AboutViewController alloc]
initWithNibName:#"AboutViewController" bundle:nil];
[self.window addSubview:controller.view];
[self.window makeKeyAndVisible];
If I comment out these lines, and replace it with another subview, it doesn't happen. The AboutViewController nib was the one which was localized. If I display the same view when the user clicks on an (i) information button, it just works and without the warning. It just gives me the warning when I do it from the AppDelegate.

Strange Exc Bad Access when using Init, PushViewController, Release. Anything wrong with this code?

Maybe I've been looking at this for too long ;) My app has a NavigationController and several ViewControllers. From one of the ViewControllers two levels down (mainViewController), loaded from the rootViewController, I have the code below. After the PushViewController to the dataViewController and back (e.g. back Button pressed), the app crashes.
The dataViewController loads just fine, but when the back button of the navigationController is tapped, the App crashes with Object Exception. If I remove:
[dataViewController release];
the app works fine. It's strange because the dataViewController is init'ed in the same method.
Any ideas?
- (void) locationPage
{
[[NSNotificationCenter defaultCenter] postNotificationName:#"NotifyRemoveMap" object:nil];
MyAppDelegate *app = [[UIApplication sharedApplication] delegate];
UINavigationController *navigation = app.navigationCantroller;
[navigation popToRootViewControllerAnimated:NO];
DataViewController *dataViewController = [[DataViewController alloc] initWithNibName:#"DataView" bundle:nil];
[dataViewController setCategoryId:category];
MyLanguage *lang = app.lang;
Mylocation *location = [lang locationForCategoryId:category];
dataViewController.title = location.name;
NSArray *locationArray = [lang locations];
dataViewController.locations = locationArray;
[navigation pushViewController:dataViewController animated:YES];
[dataViewController release]; // With this removed, app doesn't crash
}
Haven't even read your post. If it's Exec-Bad-Access, I have 2 words for you:
Enable NSZombies.
Follow this link: (it explains everything you need to know to fix any bad access issue)
Phone Memory Debug with NSZombie and Instruments
Cheers!
The problem probably arises when the dataViewController gets popped and you try to access something on it - it is already released then. You might check the console for more details - better yet, run in debug mode (debug configuration and running with debugger).
You can edit your question to show some code that is run with the back button.
You talk about releasing dataViewController but your code says detailsViewController. Did you copy and paste incorrectly or is that the mistake?
You should consider not to use app.navigationController but self.navigationController. Cleaner design. Less dependencies on the app delegate, which too often is used as a frankensteinobject that knows too much.

iPhone application crash (iOS4 Only)

My iPhone application occasionally crashs the first time it is run after being installed. After this every time i try and run the app it remains on the splash screen or even a black screen until eventually it dies. I have to restart the device to get the application to work. After this it works fine every time. The only change between the OS3 code and 4 is the property 'UIApplicationExitsOnSuspend' to force the app to reload every time instead of suspending. Any help would be great.
Here are the two Code snippets:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
taskListViewController = [[TaskListViewController alloc] initWithNibName:#"TaskListView" bundle:nil];
taskListViewController.managedObjectContext = self.managedObjectContext;
[taskListViewController setAppDefaults];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:taskListViewController];
[taskListViewController release];
navController.navigationBar.tintColor = [UIColor blackColor];
[window addSubview:[navController view]];
[window makeKeyAndVisible];
}
- (void)viewDidLoad
{
NSLog(#"viewDidLoad - Start");
[super viewDidLoad];
NSError *error = nil;
if(![[self fetchedResultsController] performFetch:&error])
{
NSLog(#"Error with initial fetch %#, %#", error, [error userInfo]);
}
[activityIndicator startAnimating];
self.navigationItem.leftBarButtonItem.enabled = NO;
self.navigationItem.rightBarButtonItem.enabled = NO;
infoButton.enabled = NO;
syncButton.enabled = NO;
taskListTable.userInteractionEnabled = NO;
taskListTable.allowsSelection = NO;
checkingRecovery = true;
[self insertCheck];
}
Other Methods mentioned above:
[taskListViewController setAppDefaults]
[self insertCheck];
setAppDefaults - Enumerates through the settings bundle applying the defaultValues to NSUserDefaults if they have not been set already by the user in peferences.
insertCheck - Performs some queries on the db to ensure file integrity on audio recordings but in this case as this is the first time the app is loaded it will do nothing.
Update:
I have commented out the extra method calls (the two above) and i am still having the problem.
I have found a few people having the same sort of problem on the apple developer forum with no solutions. One reply was from a user having the same problem but there application did get approved on the app store.
Thanks Sj
If you are debugging the application when it crashes, you should get a stack trace, which will show you on what line the application crashes.
If you could provide the stack trace it would be much easier to find the cause of the crash.
Have you looked at the log files?
You can copy them off your iPhone if you plug it in, load organizer (Windows->Organizer in XCode) and select device logs.
If you see a log for the time your application crashed, it should include the call stack (which should include the function causing it to crash)
Alternatively it could be that you're stuck in some code run at startup - and if your application doesn't start in a timely manor (within 30 seconds IIRC) iOS kills it.
Try it without the managedObjectContext piece and see if you are still crashing. What does the log say when you crash? Do you get a memory exception?