-
Notifications
You must be signed in to change notification settings - Fork 14
/
BackgroundApplication.m
executable file
·86 lines (76 loc) · 2.09 KB
/
BackgroundApplication.m
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// BackgroundApplication.m
//
// Created by Matthias Ringwald on 12/7/09.
// Copyright 2009 mnm. All rights reserved.
//
#import "BackgroundApplication.h"
#import <Foundation/Foundation.h>
// private API of UIApplication
@interface UIApplication (privateAPI)
- (void)applicationWillSuspend;
- (void)applicationDidResume;
- (void)applicationSuspend:(void *)fp8;
- (void)applicationSuspend:(void *)fp8 settings:(id)settings;
- (void)setApplicationBadgeString:(NSString*)fp8; // 3.x
- (void)setApplicationBadge:(NSString*)fp8; // 2.2
@end
@implementation BackgroundApplication
-(id) init {
if (!(self = [super init])) return nil;
runInBackground = NO;
return self;
}
#if 0
- (void)applicationWillSuspend {
if (!runInBackground){
[super applicationWillSuspend];
} else {
// NSLog(@"ignoring applicationWillSuspend");
}
}
- (void)applicationDidResume{
if (!runInBackground){
[super applicationDidResume];
} else {
// NSLog(@"ignoring applicationDidResume");
}
}
#endif
- (void)applicationSuspend:(void *)fp8{
if (!runInBackground){
[super applicationSuspend:fp8];
} else {
// NSLog(@"ignoring applicationSuspend %@", fp8);
}
}
#if 0
// not needed yet
- (void)applicationSuspend:(void *)fp8 settings:(id)settings {
if (!runInBackground){
[super applicationSuspend:fp8];
} else {
NSLog(@"ignoring applicationSuspend %@ settings %@", fp8, settings);
}
}
#endif
+ (void) setRunInBackground:(bool) enable {
UIApplication *app = [UIApplication sharedApplication];
if (enable) {
// @TODO 2.0 <-> 3.x
if ([app respondsToSelector:@selector(setApplicationBadgeString:)]){
[app setApplicationBadgeString:@"On"]; // SDK 3.0
} else if ([app respondsToSelector:@selector(setApplicationBadge:)]) {
[app setApplicationBadge:@"On"]; // SDK 2.0
} else {
[app setApplicationIconBadgeNumber:1]; // SDK ?
}
} else {
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
((BackgroundApplication *) [super sharedApplication])->runInBackground = enable;
}
+ (bool) runInBackground {
return ((BackgroundApplication *) [super sharedApplication])->runInBackground;
}
@end