在IOS

2015-10-26 46 views
0

我想創建的兩個日期之間的事件一樣,2015年10月1日至2015/10/05兩個日期在IOS

+0

您是否使用之間創建活動創建兩個日期之間的活動'EventKit'框架? – Adeel

+0

你能簡單解釋一下嗎? – Mehul

+0

是的即時通訊使用Eventkit框架 –

回答

0
#import <EventKit/EventKit.h> 
#import <EventKitUI/EventKitUI.h> 

-(void)yourmethodToSaveEvent { 
EKEventStore *eventStore = [[EKEventStore alloc] init]; 
[self checkForEventAuthorization:eventStore completionHandler:^(BOOL granted, NSError *error) { 
    if (granted) { 
     EKEvent *event = [EKEvent eventWithEventStore:eventStore]; 
     event.title = @"title"; 
     event.startDate = [NSDate date]; // start date 
     event.endDate = [NSDate date]; // end date ; 
     event.notes = @"notes"; 
     [event setCalendar:[eventStore defaultCalendarForNewEvents]]; 
     NSError *err; 
     BOOL isSuccess = [eventStore saveEvent:event span:EKSpanThisEvent error:&err]; 
     if(isSuccess) { 
      NSLog (@"your event saved successfully."); 

     } else { 
      NSLog (@"failed."); 
     } 
    } 
}]; 
} 

-(void)checkForEventAuthorization:(EKEventStore *)eventStore completionHandler:(void (^)(BOOL granted, NSError *error))block { 
if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) { 
     // iOS 6 and later 
    [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { 
     block (granted,error); 
    }]; 
} else { 
    block (YES,nil); 
} 
} 
+0

請檢查這個鏈接和這個程序添加兩個日期的事件,請幫助我https://github.com/muhku/calendar-ui –