- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
问题:由于我有重复规则,如何正确设置提醒截止日期?
这是提醒对象的样子:
EKReminder <0x1700cf490> {title = Dickens's CANINE GOLD WELLNESS doses[1.00]; **dueDate = (null)**; **completionDate = (null)**; priority = 0; calendarItemIdentifier = D1D99FEA-2BFA-4DB1-9D86-7FB26246B50A; alarms = (
"EKAlarm <0x1780a9420> {triggerInterval = -79200.000000}"
)}
我得到的错误是:
Reminder Error=[A repeating reminder must have a due date.]
你可以在代码中看到,我正在使用 NSDateComponents 作为解决方案,因为 startDateComponents 我只是设置月/日/年和本地时区reminder 会产生一整天的提醒,在这种情况下很好。完成后,我可能会在重复部分内移动日期组件和截止日期设置。
这是我的代码:
-(void)setReminders:(NSString *)reminderText
andDate:(NSString *)reminderdate
andPetName:(NSString*)petName
andDose:(NSNumber *)dose {
EKEventStore *store = [[EKEventStore alloc] init];
NSDate * reminderNewDate = [self getDateFromString:reminderdate];
petName = [ConfigOps readProperty:kConfigOpsPetKey];
NSString *reminderTitle = [NSString stringWithFormat:@"%@'s %@", petName, reminderText];
NSUInteger doseCount = 0;
if ([dose integerValue] != 0 || dose != nil) {
doseCount = [dose integerValue];
}
else{
doseCount = 0;//NOTE: looks like purchases will have doses not reminders so set to 0 for now.
}
[store requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error) {
// access code here
EKReminder *new_reminder = [EKReminder reminderWithEventStore:store];
new_reminder.title = reminderTitle;
new_reminder.calendar = store.defaultCalendarForNewEvents;
//get the date components
NSDateComponents *comp = [[NSDateComponents alloc]init];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *weekdayComponents =
[gregorian components:(NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit |
NSWeekdayCalendarUnit) fromDate:reminderNewDate];
NSInteger day = [weekdayComponents day];
NSInteger month = [weekdayComponents month];
//NSInteger weekday = [weekdayComponents weekday];//future reference
NSInteger year = [weekdayComponents yearForWeekOfYear];
//Month is dose+month = end of reccurence
month = month + doseCount;
[comp setYear:year];
[comp setMonth:month];
[comp setDay:day];
NSDate *date = [gregorian dateFromComponents:comp];
NSTimeZone *myNSTimeZone = gregorian.timeZone;
NSDateComponents *start = new_reminder.startDateComponents;
start.timeZone = myNSTimeZone;
start.month = [weekdayComponents month];
start.day = [weekdayComponents day];
start.year = [weekdayComponents yearForWeekOfYear];
new_reminder.startDateComponents = start;
new_reminder.dueDateComponents = start;
new_reminder.completed = NO;
//Create alarm 22 hours before
double alarmAmountInSeconds = 60.0*60.0*22.0;
EKAlarm *alarm = [EKAlarm alarmWithRelativeOffset:(-1.0*alarmAmountInSeconds)];
[new_reminder addAlarm:alarm];
//new_reminder.alarms = [NSArray arrayWithObject:alarm];
//create nice text for note.
//Hey there! petName needs remindertext from your friendly clinic, clinicName!
new_reminder.notes = reminderText;
if (doseCount != 0) {
EKRecurrenceRule *recurranceRule = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency:EKRecurrenceFrequencyMonthly
interval:1
end:[EKRecurrenceEnd recurrenceEndWithOccurrenceCount:doseCount]
];
new_reminder.calendar = [store defaultCalendarForNewReminders];
[new_reminder addRecurrenceRule:recurranceRule];
}
NSError *er;
//EKEventEditViewController
BOOL success = [store saveReminder:new_reminder commit:YES error:&er];
if (success) {
// Handle here
NSString *alertMessage = [NSString stringWithFormat:@"Reminder Created for\n%@", reminderTitle];
NSString *alertTitle = @"Please check your Reminders";
UIAlertView *alertR = [[UIAlertView alloc]initWithTitle: alertTitle
message: alertMessage
delegate: self
cancelButtonTitle:nil
otherButtonTitles:@"OK",nil];
[alertR show];
}
else{
//log error
NSLog(@" Reminder Error=[%@]", [er localizedDescription]);
//log to error table in database &inform Flurry?
}
}];
}
如果没有设置重复周期,则该方法有效,因为它不需要开始日期/截止日期。
最佳答案
在确定日期后(我发现返回的是 nil),我发现我必须在添加剂量时设置和结束重复规则。
这是消除错误的代码(Apple 拥有它非常有趣 - 苹果的荣誉!)。
if (doseCount != 0) {
EKRecurrenceRule *recurranceRule = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency:EKRecurrenceFrequencyMonthly
interval:1
end:[EKRecurrenceEnd recurrenceEndWithOccurrenceCount:doseCount]
];
new_reminder.calendar = [store defaultCalendarForNewReminders];
//FIX for : recuurence end - Reminder Error = [A repeating reminder must have a due date.]
EKRecurrenceEnd *endRec = [EKRecurrenceEnd recurrenceEndWithEndDate:date];
EKRecurrenceRule *recur = [[EKRecurrenceRule alloc]initRecurrenceWithFrequency:EKRecurrenceFrequencyDaily interval: 1 end:endRec];
unsigned unitFlags= NSYearCalendarUnit|NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit |NSMinuteCalendarUnit|NSSecondCalendarUnit|NSTimeZoneCalendarUnit;
NSDateComponents *dailyComponents=[gregorian components:unitFlags fromDate:date];
[new_reminder setDueDateComponents:dailyComponents];
[new_reminder addRecurrenceRule:recur];
//add it.
[new_reminder addRecurrenceRule:recurranceRule];
}
希望这可以帮助人们度过难关。
关于ios - 使用重复规则 iOS 设置带有到期日期的提醒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24699955/
我有一个java脚本代码如下,它应该改变“a”标签的颜色和 提醒他们的内部 HTML: function change(n){ for(i=1;i aaaa | bb
经过多次研究,我遇到了这个问题: 用户使用 setExactAndAllowWhileIdle 为我的应用程序设置一个警报时,每 9 分钟只能触发一次。 这导致了另一个问题,因为我的闹钟正在重复。我的
我想创建一个应用程序来保存笔记、提醒、日常任务,并希望在锁屏 上显示这些,当用户点击笔记时,应用程序将打开并使用自定义 View 和背景在屏幕上显示任务。我已经对如何执行此操作进行了大量搜索,但没有成
我正在研究 Bixby 集成,我正在浏览 Bixby 文档,我有一些关于 Bixby 提醒的营销信息,但我正在寻找如何以编程方式或通过 API 创建提醒,但我没有找到任何文档中的信息。 最佳答案 这是
例如,我希望在我休息的日子里每天在特定 channel 中显示提醒。就像是: /remind #channel @me will be on PTO 1/1/2016 until 1/5/2016 然
已关闭。此问题不符合 Stack Overflow guidelines 。目前不接受答案。 这个问题似乎与 a specific programming problem, a software al
我正在开发一个集成了提醒功能的Android应用程序。如果手机保持开机状态,通知就会起作用,但是当我关闭或重新启动手机时,我会丢失所有警报。我知道这是Android功能来提高手机效率,但我不知道该怎么
我没能在 Outlook 警报显示之前以编程方式将其消除。 Private Sub Application_Reminder(ByVal Item As Object) Dim objRem
这个问题已经有答案了: 已关闭12 年前。 Possible Duplicate: JQuery to check for duplicate ids in a DOM 假设我有一个代码:
我正在构建一个网站,我想实现一个提醒功能,当人们有任何项目或事件到期时提醒他们,或者只是提醒他们他们可能设置的任何计时器。我知道如何使用 javascript 的计时器函数来完成此操作,但我希望它一直
我有一个带有“打开提示”按钮的模式: × Arquivo
“允许主页按钮取消警报。当警报可见时按主页退出应用程序。它也应该产生与点击取消按钮相同的效果——也就是说,警报被关闭而不执行任何操作。如果你的警报没有取消按钮,请考虑在按下主页按钮时运行的代码中实现取
我有一个构造函数,然后我用它来创建对象library_science1: function librarytech(humanity,food,wood,metal,wealth) { this.hu
我该怎么做,例如,我在 users.cshtml View 中创建一个用户,它验证 ActionResult Create(RegisterModel um) 如果一切正常,我想返回 users.cs
我熟悉使用 eventstore 搜索谓词,例如 predicateForIncompleteRemindersWithDueDateStarting:Ending:Calendars: 但我正在尝试
免责声明:这实际上不是编程问题,但我觉得 stackoverflow 上的观众比其他大多数问答网站更有可能找到答案。 乔尔,请原谅我盗用了你的问题。 Joel 不久前在播客上问过这个问题,但我认为它从
我想以编程方式在日历中添加事件,并且我已经成功完成了。但是当我调用日历 Intent 时,它将打开日历,其中包含事件详细信息。用户可以在保存之前修改该事件。 所以我希望该事件不可编辑。如果能自动添加就
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我可以提醒 setter 函数来处理 newValue 吗? 例如: var test:String{ willSet{ newValue = newValue+" Kitty
OAuth 对话框读写权限您的应用似乎同时请求读取和写入权限。相反,最初请求少量权限,并在用户决定共享时请求写入权限。 最佳答案 这似乎是 Facebook 开发人员的错误。 有人有asked the
我是一名优秀的程序员,十分优秀!