Skip to content

Instantly share code, notes, and snippets.

@leftspin
Created June 27, 2014 17:14
Show Gist options
  • Save leftspin/e31795627e411c7e6a29 to your computer and use it in GitHub Desktop.
Save leftspin/e31795627e411c7e6a29 to your computer and use it in GitHub Desktop.
- (void) start
{
if(self.isCancelled)
{
self.finished = YES;
return;
}
self.executing = YES;
__block UIBackgroundTaskIdentifier delayedTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^
{
[[UIApplication sharedApplication] endBackgroundTask:delayedTask] ;
delayedTask = UIBackgroundTaskInvalid ;
self.executing = NO;
self.finished = YES;
self.failed = YES;
}];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"Sleeping long running task") ;
[NSThread sleepForTimeInterval:5] ;
NSLog(@"Waking long running task") ;
@autoreleasepool
{
GPUImageTransformFilter *transformerFilter = [[GPUImageTransformFilter alloc] init];
[transformerFilter forceProcessingAtSize:_size];
_resizedImage = [transformerFilter imageByFilteringImage:_originalImage];
NSLog(@"Got resized image: %@" , _resizedImage) ;
if(! _resizedImage)
{
self.failed = YES;
}
else
{
_originalImage = nil;
}
}
self.executing = NO;
self.finished = YES;
[[UIApplication sharedApplication] endBackgroundTask:delayedTask] ;
delayedTask = UIBackgroundTaskInvalid ;
}); // dispatch_async
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment