-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathMYBackgroundMonitor.h
44 lines (32 loc) · 1.5 KB
/
MYBackgroundMonitor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// MYBackgroundMonitor.h
// MYUtilities
//
// Created by Jens Alfke on 9/24/15.
// Copyright © 2015 Jens Alfke. All rights reserved.
//
#import <Foundation/Foundation.h>
/** Monitors when a UIKit app enters/leaves the background, and allows the client to start a
"background task" to request more time to finish an activity. */
@interface MYBackgroundMonitor : NSObject
- (instancetype) init;
/** Explicitly stops the monitor. (So does deallocing it.) */
- (void) stop;
/** Starts a background task. Should be called from the onAppBackgrounding block.
Only one background task can be active at a time. */
- (BOOL) beginBackgroundTaskNamed: (NSString*)name;
/** Tells the OS that the current background task is done.
@return YES if there was a background task, NO if none was running. */
- (BOOL) endBackgroundTask;
/** YES if there is currently a background task. */
@property (readonly) BOOL hasBackgroundTask;
/** This block will be called when the app goes into the background.
The app will soon stop being scheduled for CPU time unless the block starts a background task
by calling -beginBackgroundTaskNamed:. */
@property (strong) void (^onAppBackgrounding)();
/** Called when the app returns to the foreground. */
@property (strong) void (^onAppForegrounding)();
/** Called if the OS loses its patience before -endBackgroundTask is called.
The task is implicitly ended, and the app will soon stop being scheduled for CPU time. */
@property (strong) void (^onBackgroundTaskExpired)();
@end