提示创建失败,错误消息为NIL



我一直在为我的应用程序添加todo功能。虽然一切看起来都很正常,但我在提醒上创建失败,但错误值为NIL。这里是相关的代码-(我从一个UIViewController拉文本和日期-一切都是正确连接的)。

-(IBAction)createButtonPressed
{
    // Setup Variables for coverting date:
    int year;
    int month;
    int day;
    int hour;
    int minute;
    int second;
    NSDate *actualDate;
    NSDateComponents *dateComps;
    NSCalendar  *calendar;
    NSDateFormatter *dateFormatter;
    actualDate = dateValue.date;
    calendar = [[NSCalendar currentCalendar] copy];
    dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setTimeZone:[calendar timeZone]];
    [dateFormatter setDateFormat:@"yyyy"];
    year = [[dateFormatter stringFromDate:actualDate] intValue];
    [dateFormatter setDateFormat:@"MM"];
    month = [[dateFormatter stringFromDate:actualDate] intValue];
    [dateFormatter setDateFormat:@"dd"];
    day = [[dateFormatter stringFromDate:actualDate] intValue];
    [dateFormatter setDateFormat:@"HH"];
    hour = [[dateFormatter stringFromDate:actualDate] intValue];
    [dateFormatter setDateFormat:@"mm"];
    minute = [[dateFormatter stringFromDate:actualDate] intValue];
    [dateFormatter setDateFormat:@"ss"];
    second = [[dateFormatter stringFromDate:actualDate] intValue];
    dateComps = [[NSDateComponents alloc] init];
    [dateComps setTimeZone:[calendar timeZone]];
    [dateComps setDay:day];
    [dateComps setMonth:month];
    [dateComps setYear:year];
    // Create the Todo
    EKReminder *reminder = [EKReminder reminderWithEventStore:store];

    [reminder setTitle:self.actionText.text];
    [reminder setDueDateComponents:dateComps];
    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]);
        // Popup a messaging saying the reason why you can't create the todo.
    } else {
        // Popup a message saying the to do was created
    }

}

'这段代码的大部分是试图以正确的格式获取日期。我的NSLog显示如下:"错误保存提示:(null)"

将以下代码添加到ViewDidLoad函数

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

相关内容

  • 没有找到相关文章

最新更新