Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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
Objective c 使用目标c禁用提醒_Objective C_Reminders - Fatal编程技术网

Objective c 使用目标c禁用提醒

Objective c 使用目标c禁用提醒,objective-c,reminders,Objective C,Reminders,我正在开发一个医药提醒应用程序。用户插入药物名称和从日期选取器开始的时间,我为每个药物创建一个提醒 我的问题:当用户想要编辑任何种类药品的用药时间时,我如何删除提醒 这是我保存提醒的代码: // Get the current date NSDate *pickerDate = [datePicker date]; // Break the date up into components NSDateComponents *dateComponents = [calen

我正在开发一个医药提醒应用程序。用户插入药物名称和从日期选取器开始的时间,我为每个药物创建一个提醒

我的问题:当用户想要编辑任何种类药品的用药时间时,我如何删除提醒

这是我保存提醒的代码:

 // Get the current date

    NSDate *pickerDate = [datePicker date];
   // Break the date up into components
    NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit )      fromDate:pickerDate];

    NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ) fromDate:pickerDate];

    NSDateComponents *dateComps = [[NSDateComponents alloc] init];

    [dateComps setDay:[dateComponents day]];

    [dateComps setMonth:[dateComponents month]];

    [dateComps setYear:[dateComponents year]];

    [dateComps setHour:[timeComponents hour]];

//  // Notification will fire in one minute

    [dateComps setMinute:[timeComponents minute]];

[dateComps setSecond:[timeComponents second]];

    NSDate *itemDate = [calendar dateFromComponents:dateComps];

EKEventStore *eventStore = [[EKEventStore alloc] init];
if([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])

{
    // iOS 6 and later

    // asks user to allow application to use his device calendar

    [eventStore requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error)

     {
        if (granted)
        {
            EKReminder *reminder = [EKReminder reminderWithEventStore:eventStore];

             reminder.title = [NSString stringWithFormat: @"وقت الدواء"] ;

             reminder.calendar = [eventStore defaultCalendarForNewReminders];

            // NSDate *date = itemDate;

             EKAlarm *alarm = [EKAlarm alarmWithAbsoluteDate:itemDate];
             [reminder addAlarm:alarm];
             [EventIDArray addObject:alarm];

             NSError *error = nil;
             [eventStore saveReminder:reminder commit:YES error:&error];

             if(error)

                 NSLog(@"unable to Reminder!: Error= %@", error);
        }

     }];

}

// iOS < 6

else
我使用“删除提醒”,但提醒仍处于活动状态

[eventStore removeReminder:[EventIDArray objectAtIndex:row] commit:YES error:&error];

谢谢,非常感谢您的帮助。

要有效地取消提醒(EKReminder),您应该将completed属性设置为YES

这将自动将该提醒的completionDate设置为当前日期

如上述文档所述,您只需将属性设置为“是”即可取消提醒

对你来说,我想会是这样的:

(EKReminder *)[EventIDArray objectAtIndex:row].completed = YES;
假设对象从以下位置返回:

[EventIDArray objectAtIndex:row] 

是您希望取消的对象实例。

您需要像这样强制转换从数组返回的对象

(EKReminder *)[EventIDArray objectAtIndex:row].completed = YES;

感谢约翰·伍兹的回复,但将已完成的属性设置为“是”是什么意思?哪个属性?您好,Fadia,EkRemembers类本身有一个名为“completed”的属性,您需要将其设置为“YES”以取消给定的提醒。我已经更新了答案。如果你对此还有任何问题,请告诉我。嗨,约翰,如果你注意到我在EventArray中添加了报警,你认为这是正确的还是我应该添加itemDate?当我使用[EventIDArray objectAtIndex:row]时,completed=YES;我有以下错误:在类型为“id”的对象上找不到属性“completed”,当我放置时,所有提醒都被取消EKReminder*reminder=[EKReminder reminderWithEventStore:eventStore];提醒。完成=是;您好,Fadia,正如Mihir所提到的,您应该将id对象强制转换为一个提醒。我已经更新了我的答案-为不准确道歉,我手头没有XCode。谢谢你John和Mihir,在我将对象强制转换为类型为“id”的对象上找不到相同的错误属性“completed”
(EKReminder *)[EventIDArray objectAtIndex:row].completed = YES;