我想你的幫助我的朋友。我正在開發iphone/ipad通用應用程序。我想添加用戶選擇的多個事件(可能是1-50個事件)。這個應用程序將添加事件到iphone日曆。事件和事件日期可能有所不同。如何在沒有用戶交互的情況下向日曆添加多個事件我知道將單個事件添加到iPhone/iPad日曆,但是,我不知道要添加多個事件?請幫助我的朋友..我在谷歌搜索,但沒有得到答案?請..提前致謝。如何從iPhone/iPad應用程序添加多個事件到iPhone日曆?
感謝閱讀我可憐的英語。
Yuva.M
我想你的幫助我的朋友。我正在開發iphone/ipad通用應用程序。我想添加用戶選擇的多個事件(可能是1-50個事件)。這個應用程序將添加事件到iphone日曆。事件和事件日期可能有所不同。如何在沒有用戶交互的情況下向日曆添加多個事件我知道將單個事件添加到iPhone/iPad日曆,但是,我不知道要添加多個事件?請幫助我的朋友..我在谷歌搜索,但沒有得到答案?請..提前致謝。如何從iPhone/iPad應用程序添加多個事件到iPhone日曆?
感謝閱讀我可憐的英語。
Yuva.M
也許你有你的所有事件對象存儲在數組中,然後依次通過它,並添加一個接一個到iPhone的日曆。
謝謝Mr.KingofBliss。但是,可以添加具有不同日期的事件,而無需用戶交互?你能回答我嗎?謝謝。有沒有示例代碼? –
@Yuvaraj使用不同日期時遇到什麼問題? – KingofBliss
@KingofBilss謝謝你,我的朋友。我已經找到了從iphone應用程序向iCal添加多個事件的方式。你的回答幫助我解決了我的問題。謝謝。 –
.h file
#import <EventKit/EventKit.h>
#import <EventKitUI/EventKitUI.h>
// EKEventStore instance associated with the current Calendar application
@property (nonatomic, strong) EKEventStore *eventStore;
// Default calendar associated with the above event store
@property (nonatomic, strong) EKCalendar *defaultCalendar;
.m file
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
// Calendar event has called
self.eventStore = [[EKEventStore alloc] init];
// Check access right for user's calendar
[self checkEventStoreAccessForCalendar];
}// end viewDidLoad
- (BOOL) addAppointmentDateToCalender:(NSDate *) appointment_date {
self.defaultCalendar = self.eventStore.defaultCalendarForNewEvents;
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
// Doctor Name
NSString *doctorName = [objSpineCustomProtocol getUserDefaults:@"doctorName"];
// Title for the appointment on calender
NSString *appointment_title = [NSString stringWithFormat:@"Appointment with Dr.%@", doctorName];
event.title = appointment_title;
//[NSDate dateWithString:@"YYYY-MM-DD HH:MM:SS ±HHMM"], where -/+HHMM is the timezone offset.
event.startDate = appointment_date;
NSLog(@"Start date of appointment %@",event.startDate);
NSDate *end_date_appointment = [[NSDate alloc] initWithTimeInterval:1800 sinceDate:appointment_date];
event.endDate = end_date_appointment;
NSLog(@"End date of appointment %@",event.endDate);
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
return true;
}// end method add_appointment_date_to_calender
-(void)checkEventStoreAccessForCalendar {
NSLog(@"Method: checkEventStoreAccessForCalendar");
EKAuthorizationStatus status = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];
switch (status) {
// Update our UI if the user has granted access to their Calendar
case EKAuthorizationStatusAuthorized: [self accessGrantedForCalendar];
break;
// Prompt the user for access to Calendar if there is no definitive answer
case EKAuthorizationStatusNotDetermined: [self requestCalendarAccess];
break;
// Display a message if the user has denied or restricted access to Calendar
case EKAuthorizationStatusDenied:
case EKAuthorizationStatusRestricted:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Privacy Warning" message:@"Permission was not granted for Calendar"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
break;
default:
break;
}
}// end of emethod checkEventStoreAccessForCalendar
// Prompt the user for access to their Calendar
-(void)requestCalendarAccess
{
[self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
if (granted) {
AppointmentViewController* __weak weakSelf = self;
// Let's ensure that our code will be executed from the main queue
dispatch_async(dispatch_get_main_queue(), ^{
// The user has granted access to their Calendar; let's populate our UI with all events occuring in the next 24 hours.
[weakSelf accessGrantedForCalendar];
});
}
}];
}
// This method is called when the user has granted permission to Calendar
-(void)accessGrantedForCalendar
{
NSLog(@"Method: accessGrantedForCalendar");
// Let's get the default calendar associated with our event store
self.defaultCalendar = self.eventStore.defaultCalendarForNewEvents;
}// end of method accessGrantedForCalendar
@ Yuvaraj,你是怎麼做到的呢?我有興趣在一週的不同日子裏在三個月的過程中多次發生一次事件。我真的不想單獨添加它們。請分享:) – 2012-02-07 04:29:51