From bfe81aff5464e0255e3f03b2dd7e8c7c2f4d3362 Mon Sep 17 00:00:00 2001 From: David Sinclair Date: Tue, 26 May 2020 15:35:53 -0700 Subject: [PATCH] #1304 (not restoring state) - Fixed issue with background operations that could result in the app getting killed. --- clients/ios/Classes/NBContainerViewController.m | 14 +++++--------- clients/ios/Classes/NewsBlurAppDelegate.h | 2 ++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/clients/ios/Classes/NBContainerViewController.m b/clients/ios/Classes/NBContainerViewController.m index d7dfcaffc..3654b95d7 100644 --- a/clients/ios/Classes/NBContainerViewController.m +++ b/clients/ios/Classes/NBContainerViewController.m @@ -55,7 +55,6 @@ @property (readwrite) BOOL isHidingStory; @property (readwrite) BOOL feedDetailIsVisible; @property (readwrite) BOOL keyboardIsShown; -@property (nonatomic) UIBackgroundTaskIdentifier reorientBackgroundTask; @end @@ -230,11 +229,9 @@ if (self.feedDetailIsVisible) { // Defer this in the background, to avoid misaligning the detail views if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) { - self.reorientBackgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ - [[UIApplication sharedApplication] endBackgroundTask:self.reorientBackgroundTask]; - self.reorientBackgroundTask = UIBackgroundTaskInvalid; - }]; - [self performSelector:@selector(delayedReorientPages) withObject:nil afterDelay:0.5]; + NSString *networkOperationIdentifier = [appDelegate beginNetworkOperation]; + + [self performSelector:@selector(delayedReorientPages:) withObject:networkOperationIdentifier afterDelay:0.5]; } else { [self.storyPageControl reorientPages]; } @@ -268,10 +265,9 @@ } } -- (void)delayedReorientPages { +- (void)delayedReorientPages:(NSString *)identifier { [self.storyPageControl reorientPages]; - [[UIApplication sharedApplication] endBackgroundTask:self.reorientBackgroundTask]; - self.reorientBackgroundTask = UIBackgroundTaskInvalid; + [appDelegate endNetworkOperation:identifier]; } - (void)checkSize:(CGSize)size { diff --git a/clients/ios/Classes/NewsBlurAppDelegate.h b/clients/ios/Classes/NewsBlurAppDelegate.h index 73f1c1308..bda4a8ebd 100644 --- a/clients/ios/Classes/NewsBlurAppDelegate.h +++ b/clients/ios/Classes/NewsBlurAppDelegate.h @@ -342,6 +342,8 @@ SFSafariViewControllerDelegate> { - (void)recalculateIntelligenceScores:(id)feedId; - (void)cancelRequests; +- (NSString *)beginNetworkOperation; +- (void)endNetworkOperation:(NSString *)networkOperationIdentifier; - (void)GET:(NSString *)urlString parameters:(id)parameters success:(void (^)(NSURLSessionDataTask *, id))success