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

  • SEARCH
  • Home
  • 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 8180161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:09:23+00:00 2026-06-07T00:09:23+00:00

I am wondering how I can prevent a crash when trying to close UIDoc

  • 0

I am wondering how I can prevent a crash when trying to close UIDoc twice. I tried to make sure in my code that you (theoretically) can not close a UIDocument twice. However, it still happens sometimes and I don’t know why. If it does, the app crashes:

2012-07-06 15:24:34.470 Meernotes[11620:707] ... doc state:Normal
2012-07-06 15:24:34.472 Meernotes[11620:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'closeWithCompletionHandler called while document is already closing'
*** First throw call stack:
(0x3720e88f 0x34f13259 0x3720e789 0x3720e7ab 0x312681d1 0xd19db 0x96f7f 0x9593f 0xacb8f 0x30f0cd23 0x37a7f933 0x371e2a33 0x371e2699 0x371e126f 0x371644a5 0x3716436d 0x33923439 0x30f10cd5 0x94fdd 0x94f78)
terminate called throwing an exception(lldb) 

I tried to prevent the crash as follows, but it has no effect whatsoever (i.e. it will still crash):

-(void)closeDoc {

    UIDocumentState state = _selectedDocument.documentState;

    NSMutableArray * states = [NSMutableArray array];
    if (state == 0) {
        [states addObject:@"Normal"];
    }
    if (state & UIDocumentStateClosed) {
        [states addObject:@"Closed"];
    }
    if (state & UIDocumentStateInConflict) {
        [states addObject:@"In conflict"];
    }
    if (state & UIDocumentStateSavingError) {
        [states addObject:@"Saving error"];
    }
    if (state & UIDocumentStateEditingDisabled) {
        [states addObject:@"Editing disabled"];
    }
    NSLog(@"... doc state: %@", [states componentsJoinedByString:@", "]);

    if (_selectedDocument.documentState & UIDocumentStateClosed) return;

    [_selectedDocument closeWithCompletionHandler:^(BOOL success) {

        NSLog(@"Closed document.");
        // Check status
        if (!success) {
            NSLog(@"Failed to close %@", _selectedDocument.fileURL);
        } else {
            _selectedDocument = nil;
        }

    }];             
}
  • 1 1 Answer
  • 0 Views
  • 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-06-07T00:09:24+00:00Added an answer on June 7, 2026 at 12:09 am

    It looks like UIDocument doesn’t store the closing state, only normal and closed, so you’ll have to do it yourself.

    Add this to your class variables:

    BOOL _documentClosing;
    

    And add its use in your closeDoc method:

    -(void)closeDoc {
    
        if (_docClosing || (_selectedDocument.documentState & UIDocumentClosed) != 0)
            return;
        _docClosing = YES;
    
        [_selectedDocument closeWithCompletionHandler:^(BOOL success) {
    
            NSLog(@"Closed document.");
            // Check status
            if (!success) {
                NSLog(@"Failed to close %@", _selectedDocument.fileURL);
            } else {
                _selectedDocument = nil;
                _docClosing = NO;
            }
    
        }];             
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering if anyone knows a way that you can prevent browser zooming of
I'm wondering how I can make this code safer, I'm using it as login.php:
I was wondering with my colleague today whether std::vector can be implemented to make
I am trying to prevent usernames from having specific characters so they can be
was wondering how can I create a sub drop down box upon selecting a
I was wondering how can I track the current logged in user in a
I was wondering how can I control the image on the connect dialog? I
i'm wondering how can I compare in C language, a number I put on
I was wondering how can I do something similar to Facebook when a link
I was wondering how can we can use the python module networkX to implement

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.