Properly stop the stream when exiting or switching apps

This commit is contained in:
Cameron Gutman
2014-10-21 01:54:31 -04:00
parent c36fb14b15
commit 34d871403c
6 changed files with 38 additions and 7 deletions

View File

@@ -18,6 +18,7 @@
@implementation StreamFrameViewController {
ControllerSupport *_controllerSupport;
StreamManager *_streamMan;
}
- (void)viewDidLoad
@@ -28,18 +29,29 @@
_controllerSupport = [[ControllerSupport alloc] init];
StreamManager* streamMan = [[StreamManager alloc] initWithConfig:[MainFrameViewController getStreamConfiguration] renderView:self.view connectionTerminatedCallback:self];
_streamMan = [[StreamManager alloc] initWithConfig:[MainFrameViewController getStreamConfiguration] renderView:self.view connectionTerminatedCallback:self];
NSOperationQueue* opQueue = [[NSOperationQueue alloc] init];
[opQueue addOperation:streamMan];
[opQueue addOperation:_streamMan];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillResignActive:)
name:UIApplicationWillResignActiveNotification
object:nil];
}
- (void)applicationWillResignActive:(NSNotification *)notification {
[_streamMan stopStream];
[self performSegueWithIdentifier:@"returnToMainFrame" sender:self];
}
- (void)connectionTerminated {
NSLog(@"StreamFrame - Connection Terminated");
UIAlertController* conTermAlert = [UIAlertController alertControllerWithTitle:@"Connection Terminated" message:@"The connection terminated unexpectedly" preferredStyle:UIAlertControllerStyleAlert];
[conTermAlert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDestructive handler:^(UIAlertAction* action){
[self performSegueWithIdentifier:@"returnToMainFrame" sender:self];
}]];
[self presentViewController:conTermAlert animated:YES completion:nil];
[_streamMan stopStream];
}
- (void)didReceiveMemoryWarning