Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <UIKit/UIKit.h>
- @interface Background : NSObject {
- UIBackgroundTaskIdentifier bgTask;
- }
- @end
- @implementation Background
- -(void)startTask {
- [self endTask];
- if (bgTask == UIBackgroundTaskInvalid) {
- bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
- [[UIApplication sharedApplication] endBackgroundTask:bgTask];
- bgTask = UIBackgroundTaskInvalid;
- }];
- }
- }
- -(void)endTask {
- if (bgTask != UIBackgroundTaskInvalid) {
- [[UIApplication sharedApplication] endBackgroundTask:bgTask];
- bgTask = UIBackgroundTaskInvalid;
- }
- [UIApplication sharedApplication].idleTimerDisabled = NO;
- }
- static Background *bg = NULL;
- extern "C" {
- void LaunchBackgroundTaskIOS() {
- if (bg == NULL)
- bg = [[Background alloc] init];
- [bg startTask];
- }
- void StopBackgroundTaskIOS() {
- if (bg != NULL)
- [bg endTask];
- }
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement