Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reader Comments: Fix crash when the app is backgrounded #17678

Merged
merged 1 commit into from
Dec 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions WordPress/Classes/ViewRelated/Reader/ReaderCommentsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,20 @@ - (NSFetchRequest *)fetchRequest

- (void)configureCell:(UITableViewCell *)aCell atIndexPath:(NSIndexPath *)indexPath
{
// When backgrounding, the app takes a snapshot, which triggers a layout pass,
// which refreshes the cells, and for some reason triggers an assertion failure
// in NSMutableAttributedString(data:,options:,documentAttributes:) when
// the NSDocumentTypeDocumentAttribute option is NSHTMLTextDocumentType.
// *** Assertion failure in void _prepareForCAFlush(UIApplication *__strong)(),
// /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.6.21/UIApplication.m:2377
// *** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
// reason: 'unexpected start state'
// This seems like a framework bug, so to avoid it skip configuring cells
// while the app is backgrounded.
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
return;
}

Comment *comment = [self.tableViewHandler.resultsController objectAtIndexPath:indexPath];

if ([self newCommentThreadEnabled]) {
Expand Down Expand Up @@ -1306,19 +1320,7 @@ - (void)configureCell:(UITableViewCell *)aCell atIndexPath:(NSIndexPath *)indexP
};
}

// When backgrounding, the app takes a snapshot, which triggers a layout pass,
// which refreshes the cells, and for some reason triggers an assertion failure
// in NSMutableAttributedString(data:,options:,documentAttributes:) when
// the NSDocumentTypeDocumentAttribute option is NSHTMLTextDocumentType.
// *** Assertion failure in void _prepareForCAFlush(UIApplication *__strong)(),
// /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.6.21/UIApplication.m:2377
// *** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
// reason: 'unexpected start state'
// This seems like a framework bug, so to avoid it skip configuring cells
// while the app is backgrounded.
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
return;
}


NSAttributedString *attrStr = [self cacheContentForComment:comment];
[cell configureCellWithComment:comment attributedString:attrStr];
Expand Down