mirror of
https://github.com/zhigang1992/Progress-backup.git
synced 2026-01-12 08:14:32 +08:00
Add reminder methods
This commit is contained in:
@@ -15,4 +15,13 @@
|
||||
|
||||
- (void)setupEventManagerWithCompletionBlock:(void (^)(BOOL success))completionBlock;
|
||||
|
||||
|
||||
//Reminder methods
|
||||
|
||||
- (NSString *)defaultReminderListIdentifier;
|
||||
|
||||
- (NSArray *)reminderLists;
|
||||
|
||||
- (void)getReminderItemsInListWithIdentifier:(NSString *)listIdentifier includeCompleted:(BOOL)includeCompleted includeImcompleted:(BOOL)incluImcomple withCompletionBlock:(void (^)(NSArray *))completion;
|
||||
|
||||
@end
|
||||
|
||||
@@ -56,8 +56,49 @@ static PPEvenKitManager *_sharedManager;
|
||||
return [EKEventStore authorizationStatusForEntityType:EKEntityTypeReminder] == EKAuthorizationStatusAuthorized;
|
||||
}
|
||||
|
||||
#pragma mark - Reminder methods
|
||||
|
||||
- (NSString *)defaultReminderListIdentifier{
|
||||
if ([self haveAccessToReminder]){
|
||||
EKCalendar *defaultReminderList = [self.defaultStore defaultCalendarForNewReminders];
|
||||
return defaultReminderList.calendarIdentifier;
|
||||
} else {
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (NSArray *)reminderLists{
|
||||
if ([self haveAccessToReminder]){
|
||||
NSArray *reminderLists = [self.defaultStore calendarsForEntityType:EKEntityTypeReminder];
|
||||
return [reminderLists copy];
|
||||
} else {
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)getReminderItemsInListWithIdentifier:(NSString *)listIdentifier includeCompleted:(BOOL)includeCompleted includeImcompleted:(BOOL)incluImcomple withCompletionBlock:(void (^)(NSArray *))completion{
|
||||
if ([self haveAccessToReminder]){
|
||||
if (!incluImcomple && !includeCompleted) {
|
||||
completion(nil);
|
||||
} else {
|
||||
NSPredicate *reminderPredicate = nil;
|
||||
EKCalendar *calendar = [self.defaultStore calendarWithIdentifier:listIdentifier];
|
||||
if (includeCompleted && incluImcomple) {
|
||||
reminderPredicate = [self.defaultStore predicateForRemindersInCalendars:@[calendar]];
|
||||
} else if (incluImcomple && !includeCompleted) {
|
||||
reminderPredicate = [self.defaultStore predicateForIncompleteRemindersWithDueDateStarting:nil ending:nil calendars:@[calendar]];
|
||||
} else if (includeCompleted && !incluImcomple) {
|
||||
reminderPredicate = [self.defaultStore predicateForCompletedRemindersWithCompletionDateStarting:nil ending:nil calendars:@[calendar]];
|
||||
}
|
||||
[self.defaultStore fetchRemindersMatchingPredicate:reminderPredicate completion:^(NSArray *reminders) {
|
||||
completion([reminders copy]);
|
||||
}];
|
||||
}
|
||||
} else {
|
||||
completion(nil);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user