gpt4 book ai didi

ios - 提醒创建失败,错误消息为 NIL

转载 作者:行者123 更新时间:2023-11-29 13:12:21 25 4
gpt4 key购买 nike

我一直致力于为我的应用程序添加待办事项功能。虽然一切看起来都不错,但我在提醒上得到了一个失败的创建,但错误值为 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 显示以下内容:“错误保存提醒:(空)”

最佳答案

在 ViewDidLoad 函数中添加了以下代码

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

关于ios - 提醒创建失败,错误消息为 NIL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16909103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com