iPhone application crash (iOS4 Only) - iphone

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?

Related

App Crash on slow internet connections

Whenever there is a connection problem, a slow connection on 2G , etc., my app crashes with the following log:
What I can get from the log is, that it crashes on sendSynchronousRequest method of the NSURLConnection. How do I know what exactly is the problem, and how do I solve it?
I have put Reachability methods, given by Apple, but the return YES to both Internet reachability and Host reachability. It's just that the internet connection is very slow.
On Fast connections (Wifi), it works perfectly well.
Edit:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window setFrame:[[UIScreen mainScreen] bounds]];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//singleton
u=[[U5 alloc]init];
m_tUSyncPersistableConfig = [[USyncPersistableConfig alloc] init] ;
m_commonObj = [[CommonClass alloc] init] ;
u.m_tUSyncPersistableConfig=m_tUSyncPersistableConfig;
u.commonObj = m_commonObj;
//register for push notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
//load persisting data : from sqlite database
[u loadPreferences:m_tUSyncPersistableConfig];
window.rootViewController = tabBarController;
[window makeKeyAndVisible];
if (![[NSUserDefaults standardUserDefaults] boolForKey:#"HasLaunchedOnce"]) {
//first launch//setting some values
}else {
//not first launch
}
if (![[NSUserDefaults standardUserDefaults] boolForKey:#"HasLaunchedOnce"] || [u.m_tUSyncPersistableConfig.mUserName isEqualToString:#""] || !u.m_tUSyncPersistableConfig.mUserName)
{
// This is the first launch ever
//present login page
}
else
{
// app already launched
[[u commonObj] performSelectorInBackground:#selector(getAccountInfo) withObject:nil];
}
return YES;
}
I would strongly recommend moving away from synchronous NSURLConnection web requests. It's not recommended by Apple and is considered bad design. I suggest moving to asynchronous requests -- it might sidestep your problem, and you can handle errors with the NSURLConnection delegate method.
Running synchronous requests in background threads is fine in general.
But the crash report shows that the synchronous request is running on the main thread. So there is at least one location where you are not running it in the background thread. And on the main thread it will block the UI and the iOS watchdog process will notice this and kill the app on startup.
So make sure, that you are never ever using synchronous requests on the main thread!
You are saying that you are doing this, but maybe you are doing it wrong. Show the code that is actually calling the connection methods. If you symbolicate the crash report it will also show these locations in the frames 8 to 10 of the thread 0 stack trace.

Could not locate an NSManagedObjectModel for entity name - Universal App

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).

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.

Application crashes when asking if user wants to use Location Services

I have an iPhone app that is using CoreLocation.
Upon first installing the app, the iPhone system message is displayed asking whether or not the user wants to allow location services, if they click yes, my app suddenly displays the first screen of my app (I'm using a navigation controller), and crashes. This is what I see in the log -
warning: UUID mismatch detected with the loaded library - on disk is:
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/PrivateFrameworks/CoreTelephony.framework/CoreTelephony
=uuid-mismatch-with-loaded-file,file="/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/PrivateFrameworks/CoreTelephony.framework/CoreTelephony"
Program received signal: “EXC_BAD_ACCESS”.
And the stack trace looks like this
My code isn't too far off from the LocateMe sample (which works on my device). I have this:
CLLocationManager *clLocationManager = [[CLLocationManager alloc] init];
clLocationManager.delegate = self;
if (clLocationManager.locationServicesEnabled) {
[clLocationManager startUpdatingLocation];
} else {
self.searchBar.placeholder = #"Enter location";
}
Any idea on waht I'm doing wrong?
does your navigation controller support CLLocationManagerDelegate? it looks like it's crashing trying to send you an event.
what does your locationManager:didUpdateToLocation:fromLocation: function look like?
It looks like this is a byproduct of this question
To solve the problem, I wound up following this approach
Basically, in my ViewController's dealloc method -
- (void)dealloc {
locationManager.delegate = nil;
[locationManager release];
}

Objective-C iPhone - UIImagePickerController error

I'm doing something with UIImagePickerController.
It works fine and the Picture browser does open, however, I get this message.
"Failed to save the videos metadata to the filesystem. Maybe the information did not conform to a plist."
What could be causing that? That is caused by this line
[self presentModalViewController:self.imgPicker animated:YES]; which is activated on a button click
Snippets of the code that I have below.
- (void)viewDidLoad {
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.allowsImageEditing = YES;
self.imgPicker.delegate = self;
}
- (IBAction)grabImage {
[self presentModalViewController:self.imgPicker animated:YES];
}
Thanks,
Tee
Many people have seen that error. It appears to not actually have any negative impact on your app, however. So don't worry about and hope Apple fixes it in the next SDK.
Here's a thread on the Apple dev forums about it (Apple iPhone developer account required)
https://devforums.apple.com/message/144567#144567
No solutions have turned up to my knowledge.