gpt4 book ai didi

iphone - 如何在特定时间在 iOS 中设置提醒并在 2 分钟间隔后一次又一次(五次)显示它

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:29:43 24 4
gpt4 key购买 nike

我有这样的值(value)

createdate = "2013-09-24 04:29:30";

我必须在这个时间设置提醒。我正在使用本地通知来设置提醒,但我不确定在它发生后如何删除它以及如何在提醒时间两分钟后再次调用它。

提前致谢。

EKEventStore *eventStore = [[EKEventStore alloc]init];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];

//no need to fill all fill which one u want to set
event.title =@"eventTitle";
event.location = @"eventLocation";
event.notes = @"eventNote";
event.startDate = datePicker.date; //set date
event.URL = [NSURL URLWithString:@"url"];

//for alert set the aleram and notify the user rest is taken care by calendar for u

EKAlarm *alaram = [[EKAlarm alloc]init];
[alaram setAbsoluteDate:datePicker.date];
[event addAlarm:alaram];
//finally add it to calendar
NSError *err = nil;
BOOL complete = [eventStore saveEvent:event span:EKSpanThisEvent error:&err];
if(err)
{
NSLog(@"error in storing event");
}
else
NSLog(@"successfully added");

if(complete)
{
NSLog(@"successfully added");
}
else
{
NSLog(@"error in storing event");

最佳答案

我正在发布与向日历添加事件和设置剩余时间相关的代码希望你能有所了解


 - (void)addEventToCalendar
{

EKEventStore *eventStore = [[EKEventStore alloc]init];
if([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {
// iOS 6 and later
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted){

//for IOS > 6.0
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];

//no need to fill all fill which one u want to set
event.title =@"eventTitle";
event.location = @"eventLocation";
event.notes = @eventNote";
event.startDate = eventStartDate; //set date
event.endDate = eventEndTime;
event.URL = [NSURL URLWithString:@"url"];

//for alert set the aleram and notify the user rest is taken care by calendar for u

switch (evetReminder) { //set alaram for 5mins, 15mins ,20mins etc
case 0:
self.selectedAlertSetting = @"None";
break;

case 1:
{
EKAlarm *alaram = [[EKAlarm alloc]init];
[alaram setAbsoluteDate:eventStartDate];
[event addAlarm:alaram];
[alaram release];
break;
}


case 2:
{
NSTimeInterval aInterval = -5 *60;
EKAlarm *alaram = [EKAlarm alarmWithRelativeOffset:aInterval];
[event addAlarm:alaram];
break;
}
case 3:
{
NSTimeInterval aInterval = -15 * 60;
EKAlarm *alaram = [EKAlarm alarmWithRelativeOffset:aInterval];
[event addAlarm:alaram];
break;
}
case 4:
{
NSTimeInterval aInterval = -30 * 60;
EKAlarm *alaram = [EKAlarm alarmWithRelativeOffset:aInterval];
[event addAlarm:alaram];
break;
}
case 5:
{
NSTimeInterval aInterval = -1 * 60 * 60;
EKAlarm *alaram = [EKAlarm alarmWithRelativeOffset:aInterval];
[event addAlarm:alaram];
break;
}
case 6:
{
NSTimeInterval aInterval = -2 * 60 * 60;
EKAlarm *alaram = [EKAlarm alarmWithRelativeOffset:aInterval];
[event addAlarm:alaram];
break;
}

case 7:
{
NSTimeInterval aInterval = -1 * 24 * 60 * 60;
EKAlarm *alaram = [EKAlarm alarmWithRelativeOffset:aInterval];
[event addAlarm:alaram];
break;
}
case 8:
{
NSTimeInterval aInterval = -2 * 24 * 60 * 60;
EKAlarm *alaram = [EKAlarm alarmWithRelativeOffset:aInterval];
[event addAlarm:alaram];
break;
}
default:
break;
}

//finally add it to calendar
NSError *err = nil;
BOOL complete = [eventStore saveEvent:event span:EKSpanThisEvent error:&err];
if(err)
{
NSLog(@"error in storing event");
}
else
NSLog(@"successfully added");

if(complete)
{
NSLog(@"successfully added");
}
else
{
NSLog(@"error in storing event");
}

[eventStore release];

}

}];

}
else
{
//for IOS < 6.0
// perform same action hear
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];

//no need to fill all fill which one u want to set
event.title =@"eventTitle";
event.location = @"eventLocation";
event.notes = @eventNote";
event.startDate = eventStartDate; //set date
event.endDate = eventEndTime;
event.URL = [NSURL URLWithString:@"url"];

//for alert set the aleram and notify the user rest is taken care by calendar for u

switch (evetReminder) { //set alaram for 5mins, 15mins ,20mins etc
case 0:
self.selectedAlertSetting = @"None";
break;

case 1:
{
EKAlarm *alaram = [[EKAlarm alloc]init];
[alaram setAbsoluteDate:eventStartDate];
[event addAlarm:alaram];
[alaram release];
break;
}


case 2:
{
NSTimeInterval aInterval = -5 *60;
EKAlarm *alaram = [EKAlarm alarmWithRelativeOffset:aInterval];
[event addAlarm:alaram];
break;
}
case 3:
{
NSTimeInterval aInterval = -15 * 60;
EKAlarm *alaram = [EKAlarm alarmWithRelativeOffset:aInterval];
[event addAlarm:alaram];
break;
}
case 4:
{
NSTimeInterval aInterval = -30 * 60;
EKAlarm *alaram = [EKAlarm alarmWithRelativeOffset:aInterval];
[event addAlarm:alaram];
break;
}
case 5:
{
NSTimeInterval aInterval = -1 * 60 * 60;
EKAlarm *alaram = [EKAlarm alarmWithRelativeOffset:aInterval];
[event addAlarm:alaram];
break;
}
case 6:
{
NSTimeInterval aInterval = -2 * 60 * 60;
EKAlarm *alaram = [EKAlarm alarmWithRelativeOffset:aInterval];
[event addAlarm:alaram];
break;
}

case 7:
{
NSTimeInterval aInterval = -1 * 24 * 60 * 60;
EKAlarm *alaram = [EKAlarm alarmWithRelativeOffset:aInterval];
[event addAlarm:alaram];
break;
}
case 8:
{
NSTimeInterval aInterval = -2 * 24 * 60 * 60;
EKAlarm *alaram = [EKAlarm alarmWithRelativeOffset:aInterval];
[event addAlarm:alaram];
break;
}
default:
break;
}

//finally add it to calendar
NSError *err = nil;
BOOL complete = [eventStore saveEvent:event span:EKSpanThisEvent error:&err];
if(err)
{
NSLog(@"error in storing event");
}
else
NSLog(@"successfully added");

if(complete)
{
NSLog(@"successfully added");
}
else
{
NSLog(@"error in storing event");
}



[eventStore release];
}

}


关于iphone - 如何在特定时间在 iOS 中设置提醒并在 2 分钟间隔后一次又一次(五次)显示它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19043069/

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