Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在iOS中设置特定时间的提醒,并在该时间间隔2分钟后一次又一次(五次)显示提醒_Iphone_Ios_Ios6_Notifications_Local - Fatal编程技术网

Iphone 如何在iOS中设置特定时间的提醒,并在该时间间隔2分钟后一次又一次(五次)显示提醒

Iphone 如何在iOS中设置特定时间的提醒,并在该时间间隔2分钟后一次又一次(五次)显示提醒,iphone,ios,ios6,notifications,local,Iphone,Ios,Ios6,Notifications,Local,我有自己的价值 createdate=“2013-09-24 04:29:30” 我必须在这段时间设置提醒。我正在使用本地通知设置提醒,但我不确定在提醒发生后如何删除它,以及在提醒两分钟后如何再次调用它 提前谢谢 EKEventStore *eventStore = [[EKEventStore alloc]init]; EKEvent *event = [EKEvent eventWithEventStore:eventStore]; [event setCalendar:[eventStor

我有自己的价值

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

 }
-(作废)添加日历
{
EKEventStore*eventStore=[[EKEventStore alloc]init];
if([eventStore respondsToSelector:@selector(requestAccessToEntityType:完成:)])){
//iOS 6及更高版本
[eventStore requestAccessToEntityType:eEntityTypeEvent completion:^(已授予布尔,N错误*错误){
如果(授予){
//对于IOS>6.0
EKEvent*event=[EKEvent eventWithEventStore:eventStore];
[事件设置日历:[eventStore defaultCalendarForNewEvents]];
//不需要填写所有要设置的内容
event.title=@“eventTitle”;
event.location=@“eventLocation”;
event.notes=@eventNote”;
event.startDate=eventStartDate;//设置日期
event.endDate=eventEndTime;
event.URL=[NSURL URLWithString:@“URL”];
//对于警报,设置aleram并通知用户rest由日历处理
开关(evetReminder){//设置5分钟、15分钟、20分钟等的alaram
案例0:
self.selectedAlertSetting=@“无”;
打破
案例1:
{
EKAlarm*alaram=[[EKAlarm alloc]init];
[alaram setAbsoluteDate:eventStartDate];
[事件添加报警:alaram];
[阿拉姆释放];
打破
}
案例2:
{
NSTimeInterval aInterval=-5*60;
EKAlarm*Alarm=[EKAlarm Alarm With Relative Offset:aInterval];
[事件添加报警:alaram];
打破
}
案例3:
{
NSTimeInterval aInterval=-15*60;
EKAlarm*Alarm=[EKAlarm Alarm With Relative Offset:aInterval];
[事件添加报警:alaram];
打破
}
案例4:
{
NSTimeInterval aInterval=-30*60;
EKAlarm*Alarm=[EKAlarm Alarm With Relative Offset:aInterval];
[事件添加报警:alaram];
打破
}
案例5:
{
NSTimeInterval aInterval=-1*60*60;
EKAlarm*Alarm=[EKAlarm Alarm With Relative Offset:aInterval];
[事件添加报警:alaram];
打破
}
案例6:
{
NSTimeInterval aInterval=-2*60*60;
EKAlarm*Alarm=[EKAlarm Alarm With Relative Offset:aInterval];
[事件添加报警:alaram];
打破
}
案例7:
{
NSTimeInterval aInterval=-1*24*60*60;
EKAlarm*Alarm=[EKAlarm Alarm With Relative Offset:aInterval];
[事件添加报警:alaram];
打破
}
案例8:
{
NSTimeInterval aInterval=-2*24*60*60;
EKAlarm*Alarm=[EKAlarm Alarm With Relative Offset:aInterval];
[事件添加报警:alaram];
打破
}
违约:
打破
}
//最后将其添加到日历中
n错误*err=nil;
BOOL complete=[eventStore saveEvent:event span:ekspan此事件错误:&err];
如果(错误)
{
NSLog(@“存储事件时出错”);
}
其他的
NSLog(@“已成功添加”);
如果(完成)
{
NSLog(@“已成功添加”);
}
其他的
{
NSLog(@“存储事件时出错”);
}
[事件商店发布];
}
}];
}
其他的
{
//对于IOS<6.0
//表演同样的动作
EKEvent*event=[EKEvent eventWithEventStore:eventStore];
[事件设置日历:[eventStore defaultCalendarForNewEvents]];
//不需要填写所有要设置的内容
event.title=@“eventTitle”;
event.location=@“eventLocation”;
event.notes=@eventNote”;
event.startDate=eventStartDate;//设置日期
event.endDate=eventEndTime;
event.URL=[NSURL URLWithString:@“URL”];
//对于警报,设置aleram并通知用户rest由日历处理
开关(evetReminder){//设置5分钟、15分钟、20分钟等的alaram
案例0:
self.selectedAlertSetting=@“无”;
打破
案例1:
{
EKAlarm*alaram=[[EKAlarm alloc]init];
[alaram setAbsoluteDate:eventStartDate];
[事件添加报警:alaram];
[阿拉姆释放];
打破
}
案例2:
{
NSTimeInterval aInterval=-5*60;
EKAlarm*Alarm=[EKAlarm Alarm With Relative Offset:aInterval];
[事件添加报警:alaram];
打破
}
案例3:
{
NSTimeInterval aInterval=-15*60;
EKAlarm*Alarm=[EKAlarm Alarm With Relative Offset:aInterval];
[事件添加报警:alaram];
打破
}
案例4:
{
NSTimeInterval aInterval=-30*60;
EKAlarm*Alarm=[EKAlarm Alarm With Relative Offset:aInterval];
[事件添加报警:alaram];
打破
}
案例5:
{
NSTimeInterval aInterval=-1*60*60;
EKAlarm*Alarm=[EKAlarm Alarm With Relative Offset:aInterval];
[事件添加报警:alaram];
打破
}
案例6:
{
NSTimeInterval aInterval=-2*60*60;
EKAlarm*Alarm=[EKAlarm Alarm With Relative Offset:aInterval];
[事件添加报警:alaram];
打破
}
案例7:
{
NSTimeInterval aInterval=-1*24*60*60;
EKAlarm*Alarm=[EKAlarm Alarm With Relative Offset:aInterval];
[事件添加报警:alaram];
打破
}
案例8:
{
NSTimeInterval aInterval=-2*24*60*60;
EKAlarm*Alarm=[EKAlarm Alarm With Relative Offset:aInterval];
[事件添加报警:alaram];
打破
}
违约:
打破
}
//最后将其添加到日历中
n错误*err=nil;
BOOL complete=[eventStore saveEvent:event span:ekspan此事件错误:&err];
如果(错误)
{
NSLog(@“存储事件时出错”);
}
其他的
NSLog(@)成功
  EKEventStore *eventStore = [[EKEventStore alloc] init] ;
  EKEvent *event = [EKEvent eventWithEventStore:eventStore];
   if([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {
    // iOS 6 and later
    [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted,   NSError *error) {
        if (granted){
            //---- codes here when user allow your app to access theirs' calendar.
            [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"];
            NSDate *newDate = [datePicker.date dateByAddingTimeInterval:24.0f * 60.0f * 60.0f + 120.0f];
            event.endDate= newDate ;
            //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");
            }
        }else
        {
            //----- codes here when user NOT allow your app to access the calendar.
        }
    }];
}
else {
    //---- codes here for IOS < 6.0.
    //[self performCalendarActivity:eventStore];
}