I have a basic implementation of UITableViewController
that presents a UIDocument
. A reference to the document is kept as instance variable of the view controller.
In viewWillDisappear:
I close the document if the view controller is removed (and not a sub-viewcontroller pushed to the stack):
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if (!self.keepDocumentOpenAfterNavigatingAway) {
[self.deckDocument closeWithCompletionHandler:^(BOOL success){
// As side effect, this retains 'self' until
// the document is closed:
self.document = nil;
}];
}
}
Now, once in a while I receive crash reports caused by this (app is for iOS 7):
objc_msgSend() selector name: _setInConflict:
I suspect that maybe the view controller was deallocated without viewWillDisappear:
being called. Then the document would have been deallocated along with it without being closed. When the conflict comes in from iCloud, the app crashes.
Maybe this happens while the app is in the background and runs low on memory? Is there such a scenario where a view controller would get deallocated without viewWillDisappear:
being called?
EDIT: To clarify, this only happens in production, I was not able to reproduce this myself. That's why I'm assuming it might be related to a low memory/background scenario. I issued low memory warnings in the simulator, without any luck.