Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1028265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:21:38+00:00 2026-05-16T12:21:38+00:00

My app is crashing when testing on the device, but not on the simulator.

  • 0

My app is crashing when testing on the device, but not on the simulator. It happens when I go to log out. I’m deleting all records from core data when the user logs out, code as follows:

-(IBAction)logOut
{
    UIAlertView *getConfirmation = [[UIAlertView alloc] initWithTitle:@"Confirm" message:@"Are you sure you want to logout. You will lose any unsync'ed workouts." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Logout", nil];
    [getConfirmation show]; 
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1){
        // Clear the database of all objects when the user logs out.
        [self deleteAllObjects:@"Workout"];
        [self deleteAllObjects:@"Route"];
        [self deleteAllObjects:@"WayPoint"];
        [self deleteAllObjects:@"Graphs"];
        [self deleteAllObjects:@"userSettings"];

        [self presentModalViewController:loginViewController animated:NO];
    }   
}


-(void)deleteAllObjects:(NSString *)entityDescription{
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:entityDescription inManagedObjectContext:managedObjectContext];
    [fetchRequest setEntity:entity];

    NSError *error;
    NSArray *items = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
    [fetchRequest release];

    for (NSManagedObject *managedObject in items) {
        [managedObjectContext deleteObject:managedObject];
        NSLog(@"%@ object deleted", entityDescription);
    }

    if (![managedObjectContext save:&error]) {
        NSLog(@"Error deleting %@ - error:%@",entityDescription,error);
    }
}

It seems to be happening when the I log in and log out straight away. In this case there would be no objects on 4 of the 5 tables (note: userSettings would have 1 record).

Looking at the console the error message is ‘*** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation.”, looking at the debugger its happening on the line if (![managedObjectContext save:&error]).

I’m not quite sure why this is happening, there would be no records in the table ‘Workout’ at this point, therefore there would be nothing to delete. The simulator seems to handle this with no problems.

Details of the Persistent Store code:

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {

    if (persistentStoreCoordinator != nil) {
        return persistentStoreCoordinator;
    }

    NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"LegginitCoreData.sqlite"]];

    NSError *error;
    persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
    if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error]) {
        // Handle error
    }    

    return persistentStoreCoordinator;
}

Any help would be much appreciated, I’m stuck on this one not and not sure where to go from here.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T12:21:39+00:00Added an answer on May 16, 2026 at 12:21 pm

    As Martin stated your error seems to be centered around the NSPersistentStore issue. Handing that error instead of having a comment of // Handle error would be a very good first step. It is quite possible you are getting an error right there and ignoring it.

    In addition, on exit, if it is your goal to delete all data, there is an easier way.

    Tear down the Core Data stack (releasing the NSManagedObjectContext, NSPersistentStoreCoordinator and the NSManagedObjectModel) and then delete the SQLite file. On next launch, all data is gone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My app was crashing only when not running using XCode debugger. It was hard
My iOS app is randomly crashing but I don't get any warning/error in the
I have an Android app which is crashing on some phones, and not on
A .Net 4.0 app keeps crashing for a user, but just for him, I
I'm having some issues with an iPhone app crashing when it comes from background,
My app keeps crashing when changing from a game screen back to the menu.
Possible Duplicate: iOS5 Stable App Crashing in iOS4.3 Simulator I have a UIViewController with
My app is crashing after loading thumbnails. On this line the code is downloading
I'm using Qt 4.7.0 (32 bit) on Windows(mingw32). The app is crashing when setVisible(),setDisabled(),hide()
I have an odd problem that is crashing my app, that I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.