From fcc770d82098ba9c2fb9fe6cdd0f3e3c45287677 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 31 May 2018 00:46:41 -0700 Subject: [PATCH] Avoid firing off HTTP requests as we enter the background when entering home from streaming --- .../ViewControllers/MainFrameViewController.m | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/Limelight/ViewControllers/MainFrameViewController.m b/Limelight/ViewControllers/MainFrameViewController.m index 0687dd4..a4be5c5 100644 --- a/Limelight/ViewControllers/MainFrameViewController.m +++ b/Limelight/ViewControllers/MainFrameViewController.m @@ -42,6 +42,7 @@ NSArray* _sortedAppList; NSCache* _boxArtCache; UIButton* _pullArrow; + bool _background; } static NSMutableSet* hostList; @@ -620,6 +621,11 @@ static NSMutableSet* hostList; name: UIApplicationWillEnterForegroundNotification object: nil]; + [[NSNotificationCenter defaultCenter] addObserver: self + selector: @selector(handleEnterBackground) + name: UIApplicationWillResignActiveNotification + object: nil]; + [self updateHosts]; [self.view addSubview:hostScrollView]; [self.view addSubview:_pullArrow]; @@ -632,12 +638,23 @@ static NSMutableSet* hostList; -(void)handleReturnToForeground { + _background = NO; + + [_discMan startDiscovery]; + // This will refresh the applist when a paired host is selected if (_selectedHost != nil && _selectedHost.pairState == PairStatePaired) { [self hostClicked:_selectedHost view:nil]; } } +-(void)handleEnterBackground +{ + _background = YES; + + [_discMan stopDiscovery]; +} + - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; @@ -651,9 +668,14 @@ static NSMutableSet* hostList; [self.navigationController.navigationBar setShadowImage:fakeImage]; [self.navigationController.navigationBar setBackgroundImage:fakeImage forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault]; - [_discMan startDiscovery]; - - [self handleReturnToForeground]; + // We can get here on home press while streaming + // since the stream view segues to us just before + // entering the background. We can't check the app + // state here (since it's in transition), so we have + // to use this variable that we set. + if (!_background) { + [_discMan startDiscovery]; + } } - (void)viewDidDisappear:(BOOL)animated