Skip to content
Snippets Groups Projects
Commit ef970584 authored by Maxime Graulich's avatar Maxime Graulich
Browse files

iOS: compute is now allowed in background + notification

parent f248e026
Branches
Tags
No related merge requests found
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
double scaleFactor; double scaleFactor;
UIBarButtonItem *_runStopButton; UIBarButtonItem *_runStopButton;
UIAlertView *_loadingAlert; UIAlertView *_loadingAlert;
UIBackgroundTaskIdentifier _computeBackgroundTaskIdentifier;
} }
- (IBAction)pinch:(UIPinchGestureRecognizer *)sender; - (IBAction)pinch:(UIPinchGestureRecognizer *)sender;
......
...@@ -101,26 +101,35 @@ ...@@ -101,26 +101,35 @@
[_progressLabel setHidden:NO]; [_progressLabel setHidden:NO];
[_progressIndicator setHidden:NO]; [_progressIndicator setHidden:NO];
[_progressIndicator startAnimating]; [_progressIndicator startAnimating];
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_group_t group = dispatch_group_create();
dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
_computeBackgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
[[UIApplication sharedApplication] endBackgroundTask: _computeBackgroundTaskIdentifier];
_computeBackgroundTaskIdentifier = UIBackgroundTaskInvalid;
}];
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
appDelegate->compute = YES; appDelegate->compute = YES;
onelab_cb("compute"); onelab_cb("compute");
[self performSelectorOnMainThread:@selector(didStopCompute:) withObject:nil waitUntilDone:YES];
appDelegate->compute = NO; appDelegate->compute = NO;
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif) {
localNotif.alertBody = @"Computation finished";
localNotif.alertAction = @"View";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
[[UIApplication sharedApplication] endBackgroundTask: _computeBackgroundTaskIdentifier];
_computeBackgroundTaskIdentifier = UIBackgroundTaskInvalid;
}); });
}
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
- (void)didStopCompute:(id)sender [_runStopButton setAction:@selector(compute)];
{ [_runStopButton setTitle:@"Run"];
[self performSelectorOnMainThread:@selector(didStopCompute) withObject:nil waitUntilDone:NO]; [_progressLabel setHidden:YES];
} [_progressIndicator stopAnimating];
- (void)didStopCompute [_progressIndicator setHidden:YES];
{ });
[_runStopButton setAction:@selector(compute)];
[_runStopButton setTitle:@"Run"];
[_progressLabel setHidden:YES];
[_progressIndicator stopAnimating];
[_progressIndicator setHidden:YES];
} }
- (void)stop - (void)stop
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment