我正在创建一个简单的笔记应用程序,我想实现提醒。用户可以输入一条注释,点击一个按钮,然后它就会使用文本在“提醒”应用程序中设置提醒。这可能吗?如果可以,我该怎么做?我看过 Apple 关于 EventKit 和 EKReminders 的文档,但没有任何帮助。
来自《日历和提醒编程指南》 http://developer.apple.com/library/ios/#documentation/DataManagement/Conceptual/EventKitProgGuide/Introduction/Introduction.html?具体来说《阅读和写作提醒》 http://developer.apple.com/library/ios/#documentation/DataManagement/Conceptual/EventKitProgGuide/ReadingAndWritingReminders/ReadingAndWritingReminders.html#//apple_ref/doc/uid/TP40009765-CH5-SW1
您可以使用以下方式创建提醒reminderWithEventStore:
类方法。这title
and calendar
属性是必需的。提醒的日历是与其分组的列表。
在创建提醒之前,请先请求许可:
In the .h
:
@interface RemindMeViewController : UIViewController
{
EKEventStore *store;
}
and the .m
,当您需要访问提醒时:
store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeReminder
completion:^(BOOL granted, NSError *error) {
// Handle not being granted permission
}];
实际添加提醒。这是异步发生的,因此如果您尝试在此之后立即添加提醒,它将失败(根据我的经验,应用程序会崩溃)。
- (IBAction)addReminder:(id)sender
{
EKReminder *reminder = [EKReminder reminderWithEventStore:store];
[reminder setTitle:@"Buy Bread"];
EKCalendar *defaultReminderList = [store defaultCalendarForNewReminders];
[reminder setCalendar:defaultReminderList];
NSError *error = nil;
BOOL success = [store saveReminder:reminder
commit:YES
error:&error];
if (!success) {
NSLog(@"Error saving reminder: %@", [error localizedDescription]);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)