将事件添加到iOS 7日历
在我的应用程序中,我必须在iOS 7日历中添加一个事件。我在iOS 6中制作了一个类似的应用程序,并使用了以下代码: 日历实用程序.h 在需要将事件添加到日历的控制器中,我使用了以下代码: 方法将事件添加到日历中 当我尝试在iOS 7的新应用程序中使用此代码并使用断点对其进行调试时,它从不执行方法-void addeventotcalendar:eposodecell*cell和cell:intcellID。将事件添加到iOS 7日历,ios,calendar,Ios,Calendar,在我的应用程序中,我必须在iOS 7日历中添加一个事件。我在iOS 6中制作了一个类似的应用程序,并使用了以下代码: 日历实用程序.h 在需要将事件添加到日历的控制器中,我使用了以下代码: 方法将事件添加到日历中 当我尝试在iOS 7的新应用程序中使用此代码并使用断点对其进行调试时,它从不执行方法-void addeventotcalendar:eposodecell*cell和cell:intcellID。 为什么呢?我的代码有什么问题?用于将事件添加到本机日历, 包括这两个标题 - #im
为什么呢?我的代码有什么问题?用于将事件添加到本机日历, 包括这两个标题
- #import <EventKit/EventKit.h>
- #import <EventKitUI/EventKitUI.h>
对于将事件添加到本机日历, 包括这两个标题
- #import <EventKit/EventKit.h>
- #import <EventKitUI/EventKitUI.h>
试试这是iOS示例代码。它可能会帮助您了解为什么我的代码不能正常工作?我想应该有一种方法可以在不重写整个代码的情况下将事件添加到日历中…试试这是iOS示例代码..它可能会帮助您了解我的代码无法正常工作的原因?我想应该有一种方法可以在不重写整个代码的情况下将事件添加到日历中…您不必导入您不必导入
- (void) addEventToCalendar:(EpisodeCell*)cell andCell:(int)cellID {
if ([cell.enableDisableNotification isOn]) {
EKEventStore *eventStore = [[EKEventStore alloc] init];
if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])
{
// the selector is available, so we must be on iOS 6 or newer
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error)
{
NSString *errorMessage = [NSString stringWithFormat:@"Errore: %@", error];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"InteracTV" message:errorMessage delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
}
else if (!granted)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"InteracTV" message:@"Impossibile accedere al calendario: controlla le impostazioni di privacy"delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
}
else
{
// access granted
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = cellTitle;
if (cellID == 0) {
[calendarUtility setupEventForCalendarWithEvent:event andEventStore:eventStore andCellDateTime:cellDateTime1];
[self animationForInsertedEventInCalendar];
} else {
[calendarUtility setupEventForCalendarWithEvent:event andEventStore:eventStore andCellDateTime:cellDateTime2];
[self animationForInsertedEventInCalendar];
}
}
});
}];
}
else
{
// this code runs in iOS 4 or iOS 5
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = cellTitle;
if (cellID == 0) {
[calendarUtility setupEventForCalendarWithEvent:event andEventStore:eventStore andCellDateTime:cellDateTime1];
[self animationForInsertedEventInCalendar];
} else {
[calendarUtility setupEventForCalendarWithEvent:event andEventStore:eventStore andCellDateTime:cellDateTime2];
[self animationForInsertedEventInCalendar];
}
}
// // PARTE PER iOS < 6 NON IMPLEMENTATO
// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Bitmama iTv" message:@"Aggiorna il dispositivo almeno ad iOS 6 se vuoi aggiungere un evento al calendario." delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
// [alert show];
} else {
[calendarUtility deleteEventFromCalendarWithCellID:cellID];
[self animationForDeletedEventFromCalendar];
}
}
- (void)animationForInsertedEventInCalendar {
[UIView transitionWithView:self.imageViewOk duration:0.5 options:UIViewAnimationOptionAllowAnimatedContent animations:^(void){ [self.imageViewOk setAlpha:1.0]; } completion:^(BOOL finished)
{
[UIView transitionWithView:self.imageViewOk
duration:0.5 options:UIViewAnimationOptionAllowAnimatedContent
animations:^(void){ [self.imageViewOk setAlpha:0.0]; } completion:nil];
}];
}
- (void)animationForDeletedEventFromCalendar {
[UIView transitionWithView:self.imageViewDelete duration:0.5 options:UIViewAnimationOptionAllowAnimatedContent animations:^(void){ [self.imageViewDelete setAlpha:1.0]; } completion:^(BOOL finished)
{
[UIView transitionWithView:self.imageViewDelete
duration:0.5 options:UIViewAnimationOptionAllowAnimatedContent
animations:^(void){ [self.imageViewDelete setAlpha:0.0]; } completion:nil];
}];
}
- #import <EventKit/EventKit.h>
- #import <EventKitUI/EventKitUI.h>
EKEventStore *eventStore=[[EKEventStore alloc] init];
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
if (granted)
{
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
NSString * NoteDetails =@"Event detail";
NSDate *startDate = [NSDate date];
//Create the end date components
NSDateComponents *tomorrowDateComponents = [[NSDateComponents alloc] init];
tomorrowDateComponents.day = 1;
NSDate *endDate = [[NSCalendar currentCalendar] dateByAddingComponents:tomorrowDateComponents
toDate:startDate
options:0];
event.title =@"Your Event TITLE";
event.startDate=startDate;
event.endDate=endDate;
event.notes = appointmentDetail;
event.allDay=YES;
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
}
else
{
NSLog(@"NoPermission to access the calendar");
}
}];