加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – 在提醒Objective-C中为事件添加id

发布时间:2020-12-14 17:32:06 所属栏目:百科 来源:网络整理
导读:我在我的应用程序中使用Eventkit.framework添加提醒事件,但是当我在我的应用程序中显示提醒事件时,它会显示iPhone中的所有提醒事件,但我只想显示我添加的提醒事件. 这是我使用模态视图控制器添加事件的代码 EKEventEditViewController *addController = [[EK
我在我的应用程序中使用Eventkit.framework添加提醒事件,但是当我在我的应用程序中显示提醒事件时,它会显示iPhone中的所有提醒事件,但我只想显示我添加的提醒事件.

这是我使用模态视图控制器添加事件的代码

EKEventEditViewController *addController = [[EKEventEditViewController alloc] initWithNibName:nil bundle:nil];
EKEvent * eve = [EKEvent eventWithEventStore:self.eventStore];

addController.eventStore = self.eventStore;
addController.event = eve;
[self presentModalViewController:addController animated:YES];

这是用于检索提醒事件的代码

self.eventStore = [[EKEventStore alloc] init];
self.eventsList = [[NSMutableArray alloc] initWithArray:0];

self.defaultCalendar = [self.eventStore defaultCalendarForNewEvents];
self.navigationController.delegate = self;
[self.eventsList addObjectsFromArray:[self fetchEventsForToday]];

获取事件方法

- (NSArray *)fetchEventsForToday {

    NSDate *startDate = [NSDate date];
    NSDate *endDate = [NSDate dateWithTimeIntervalSinceNow:86400];

    NSArray *calendarArray = [NSArray arrayWithObject:defaultCalendar];

    NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate endDate:endDate
                                                                    calendars:calendarArray];

    NSArray *events = [self.eventStore eventsMatchingPredicate:predicate];
    return events;
}

解决方法

每个事件都有eventIdentifier属性,这是每个事件的唯一标识字符串.当您的应用添加事件时,它可以将eventIdentifiers存储在其应用程序数据中,然后在每次启动时加载该列表.您可以通过确保[self.eventStore eventWithIdentifier:identifier]确保未删除事件;返回有效的EKEvent.如果要显示应用添加的事件列表,您只需获取与您保存的标识符匹配的事件即可.由于标识符永远不会被重复使用,因此添加和删除应用程序之外的事件的用户不会影响此系统.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读