以编程方式向“提醒"应用添加提醒 [英] Programatically add a reminder to the Reminders app

查看:120
本文介绍了以编程方式向“提醒"应用添加提醒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个简单的便笺应用程序,并且我想实现提醒.用户将键入一个便笺,点击一个按钮,它将使用文本在提醒"应用程序中设置提醒.这可能吗?如果可以,我该怎么做?我已经看过Apple关于EventKit和EKReminders的文档,但对您毫无帮助.

I'm creating a simple note application and I want to implement Reminders. The user would type a note, tap a button and it would set up a reminder in the Reminders app using the text. Is this possible, and if so, how do I do it? I have seen Apple's documentation on EventKit and EKReminders but it has been no help at all.

推荐答案

来自?特别是读写提醒"

您可以使用reminderWithEventStore:类方法创建提醒. titlecalendar属性是必需的.提醒日历是与之分组的列表.

You can create reminders using the reminderWithEventStore: class method. The title and calendar properties are required. The calendar for a reminder is the list with which it is grouped.

在创建提醒之前,请先征得您的许可:

Before you create a reminder, ask for permission:

.h中:

@interface RemindMeViewController : UIViewController
{
    EKEventStore *store;
}

.m,当您需要访问提醒时:

and the .m, when you are going to need access to Reminders:

store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeReminder
                      completion:^(BOOL granted, NSError *error) {
                          // Handle not being granted permission
                      }];

实际添加提醒.这是异步发生的,因此,如果您尝试在此之后立即添加提醒,它将失败(以我的经验崩溃了该应用程序).

To actually add the reminder. This happens asynchronously, so if you try to add a reminder immediately after this, it will fail (crashes the app in my experience).

- (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]);
    }
}

这篇关于以编程方式向“提醒"应用添加提醒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆