forked from MKSG-MugunthKumar/LocalNotifications
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMKLocalNotificationsScheduler.m
More file actions
131 lines (101 loc) · 2.86 KB
/
MKLocalNotificationsScheduler.m
File metadata and controls
131 lines (101 loc) · 2.86 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// MKLocalNotificationsScheduler.m
// LocalNotifs
//
// Created by Mugunth Kumar on 9-Aug-10.
// Copyright 2010 Steinlogic. All rights reserved.
// File created using Singleton XCode Template by Mugunth Kumar (http://mugunthkumar.com
// Permission granted to do anything, commercial/non-commercial with this file apart from removing the line/URL above
#import "MKLocalNotificationsScheduler.h"
static MKLocalNotificationsScheduler *_instance;
@implementation MKLocalNotificationsScheduler
@synthesize badgeCount = _badgeCount;
+ (MKLocalNotificationsScheduler*)sharedInstance
{
@synchronized(self) {
if (_instance == nil) {
// iOS 4 compatibility check
Class notificationClass = NSClassFromString(@"UILocalNotification");
if(notificationClass == nil)
{
_instance = nil;
}
else
{
_instance = [[super allocWithZone:NULL] init];
_instance.badgeCount = 0;
}
}
}
return _instance;
}
#pragma mark Singleton Methods
+ (id)allocWithZone:(NSZone *)zone
{
return [[self sharedInstance] retain];
}
- (id)copyWithZone:(NSZone *)zone
{
return self;
}
- (id)retain
{
return self;
}
- (unsigned)retainCount
{
return NSUIntegerMax; //denotes an object that cannot be released
}
- (void)release
{
//do nothing
}
- (id)autorelease
{
return self;
}
- (void) scheduleNotificationOn:(NSDate*) fireDate
text:(NSString*) alertText
action:(NSString*) alertAction
sound:(NSString*) soundfileName
launchImage:(NSString*) launchImage
andInfo:(NSDictionary*) userInfo
{
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = fireDate;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertBody = alertText;
localNotification.alertAction = alertAction;
if(soundfileName == nil)
{
localNotification.soundName = UILocalNotificationDefaultSoundName;
}
else
{
localNotification.soundName = soundfileName;
}
localNotification.alertLaunchImage = launchImage;
self.badgeCount ++;
localNotification.applicationIconBadgeNumber = self.badgeCount;
localNotification.userInfo = userInfo;
// Schedule it with the app
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[localNotification release];
}
- (void) clearBadgeCount
{
self.badgeCount = 0;
[UIApplication sharedApplication].applicationIconBadgeNumber = self.badgeCount;
}
- (void) decreaseBadgeCountBy:(int) count
{
self.badgeCount -= count;
if(self.badgeCount < 0) self.badgeCount = 0;
[UIApplication sharedApplication].applicationIconBadgeNumber = self.badgeCount;
}
- (void) handleReceivedNotification:(UILocalNotification*) thisNotification
{
NSLog(@"Received: %@",[thisNotification description]);
[self decreaseBadgeCountBy:1];
}
@end