2011-08-30 3 views
0

나는 내 친구들을 돕고 싶습니다. 아이폰/ipad 보편적 인 응용 프로그램을 개발하고 있습니다. 사용자가 선택한 여러 개의 이벤트 (1 ~ 50 개의 이벤트가 있음)를 추가하고 싶습니다. 이 응용 프로그램은 아이폰 캘린더에 이벤트를 추가합니다. 이벤트와 이벤트 날짜는 다를 수 있습니다. 사용자 상호 작용없이 캘린더에 여러 이벤트를 추가하는 방법은 무엇입니까? 나는 iphone/ipad 달력에 단 하나 사건을 추가하기 위하여 잘 알고있다, 그러나 나는 다수 사건을 추가하기 위하여 모른다? 제발, 친구를 도우십시오. 나는 Google에서 수색했지만 대답을 얻지 못했습니까? 제발 .. 미리 감사드립니다.iphone/ipad 앱에서 iPhone 캘린더에 여러 이벤트를 추가하는 방법은 무엇입니까?

내 가난한 영어를 읽어 주셔서 감사합니다.

Yuva.M

+0

@ Yuvaraj- 어떻게하셨습니까? 다른 요일에 3 개월 동안 여러 번 열리는 이벤트를 추가하는 데 관심이 있습니다. 나는 그것들을 개별적으로 추가하고 싶지 않습니다. Please share : –

답변

1

아마 당신은 그것을 통해 다음 배열에 루프를 모든 이벤트 객체를 저장하고 한 개씩 추가 아이폰 캘린더해야합니다.

+0

감사합니다 Mr.KingofBliss. 그러나 사용자 상호 작용없이 다른 날짜의 이벤트를 추가 할 수 있습니까? 나 한테 대답 해 줄래? 감사. 샘플 코드가 있습니까? –

+0

@Yuvaraj 다른 날짜를 사용할 때 직면 한 문제는 무엇입니까? – KingofBliss

+0

@KingofBilss 내 친구 고마워. 아이폰 앱에서 iCal에 여러 이벤트를 추가하는 방법을 찾았습니다. 당신은 내 문제를 해결하는 데 도움이되는 대답을했습니다. 감사. –

0
.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 
관련 문제