Skip to content

Fix OS X - UIBackgroundTask is only on iOS #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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