-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalendarAlertGenerator.xm
60 lines (42 loc) · 1.75 KB
/
CalendarAlertGenerator.xm
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
#import <EventKit/EventKit.h>
static int debugEventNum = 0;
%hook SBApplicationIcon
/*
// Hooking a class method
+ (id)sharedInstance {
return %orig;
}
*/
- (void)launch {
%log;
%orig;
NSLog(@"CalendarAlertGenerator: creating a calendar alert - in");
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
NSString *title = [NSString stringWithFormat:@"Test Alert %d", debugEventNum++];
event.title = title;
NSDate *timeNow = [[NSDate alloc] init];
event.startDate = [[NSDate alloc] initWithTimeInterval:65 sinceDate:timeNow];
event.endDate = [[NSDate alloc] initWithTimeInterval:60 sinceDate:event.startDate];
EKAlarm *alarm1 = [EKAlarm alarmWithRelativeOffset:-60];
NSMutableArray *myAlarmsArray = [[NSMutableArray alloc] init];
[myAlarmsArray addObject:alarm1];
event.alarms = myAlarmsArray;
[myAlarmsArray release];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
NSLog(@"CalendarAlertGenerator: creating a calendar alert - out");
NSPredicate *predicate = [eventStore predicateForEventsWithStartDate:event.startDate endDate:event.endDate calendars:nil];
NSArray *events = [eventStore eventsMatchingPredicate:predicate];
NSLog(@"CalendarAlertGenerator: matching events are: %@", events);
id eventID = nil;
for (id object in events) {
EKEvent *eventObj = (EKEvent *)object;
NSLog(@"CalendarAlertGenerator: identifier %@ for %@", [eventObj eventIdentifier], eventObj);
eventID = [eventObj eventIdentifier];
}
id loadedEvent = [eventStore eventWithIdentifier:eventID];
NSLog(@"CalendarAlertGenerator: loadedEvent for eventID %@ is %@", eventID, loadedEvent);
}
%end