Skip to content

Commit

Permalink
Merge pull request #19 from pinterest/fixOSX
Browse files Browse the repository at this point in the history
Fix OS X - UIBackgroundTask is only on iOS
  • Loading branch information
garrettmoon committed Jul 31, 2015
2 parents d4288aa + 053098a commit 8e3e0aa
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions PINCache/PINDiskCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
NSString * const PINDiskCacheSharedName = @"PINDiskCacheShared";

@interface PINBackgroundTask : NSObject
#if !defined(PIN_APP_EXTENSIONS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0
@property (atomic, assign) UIBackgroundTaskIdentifier taskID;
#endif
+ (instancetype)start;
- (void)end;
@end
Expand Down Expand Up @@ -1044,15 +1046,17 @@ @implementation PINBackgroundTask
- (instancetype)init
{
if (self = [super init]) {
#if !defined(PIN_APP_EXTENSIONS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0
_taskID = UIBackgroundTaskInvalid;
#endif
}
return self;
}

+ (instancetype)start
{
PINBackgroundTask *task = [[self alloc] init];
#if !defined(PIN_APP_EXTENSIONS)
#if !defined(PIN_APP_EXTENSIONS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0
task.taskID = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
UIBackgroundTaskIdentifier taskID = task.taskID;
task.taskID = UIBackgroundTaskInvalid;
Expand All @@ -1064,7 +1068,7 @@ + (instancetype)start

- (void)end
{
#if !defined(PIN_APP_EXTENSIONS)
#if !defined(PIN_APP_EXTENSIONS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0
UIBackgroundTaskIdentifier taskID = self.taskID;
self.taskID = UIBackgroundTaskInvalid;
[[UIApplication sharedApplication] endBackgroundTask:taskID];
Expand Down

0 comments on commit 8e3e0aa

Please sign in to comment.