2012-04-12 8 views
0

Ich bin auf der Suche nach Tutorials/Richtlinien zum Importieren von iPhone Kalenderereignissen in meine App.Wie importiere ich ein iPhone Kalender Event in meine App?

Kann jemand helfen?

Dank

+0

Mögliche duplizieren [Programmatically benutzerdefinierte Ereignis im iPhone-Kalender hinzufügen] (http: // Stackoverflow .com/fragen/246249/programmatisch ly-add-custom-event-im-iphone-kalender) – 0xDE4E15B

Antwort

0
-(void)EventList{ 

EKEventStore *eventStore = [[EKEventStore alloc] init]; 
if([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) { 
    // iOS 6 and later 
    ReadCalendar = TRUE; 

    [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { 
     if (granted){ 
      //---- codes here when user allow your app to access theirs' calendar. 
      [self performCalendarActivity]; 
     }else 
     { 
      //----- codes here when user NOT allow your app to access the calendar. 
     } 
    }]; 
} 
else { 
    //---- codes here for IOS < 6.0. 
    [self performCalendarActivity]; 
} 

}

-(void)performCalendarActivity{ 
    self.eventStore = [[EKEventStore alloc] init]; 

    eventsList = [[NSMutableArray alloc] initWithArray:0]; 

    // Get the default calendar from store. 
    self.defaultCalendar = [self.eventStore defaultCalendarForNewEvents]; 

    eventsList= [[self fetchEventsForToday] mutableCopy]; 

}

-(NSArray *)fetchEventsForToday { 
NSDate *startDate; 
    NSDate *endDate; 
    startDate = [NSDate date]; 
    endDate = [NSDate dateWithTimeIntervalSinceNow:86400]; 

// Create the predicate. Pass it the default calendar. 
NSArray *calendarArray = [NSArray arrayWithObject:defaultCalendar]; 
NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate endDate:endDate 
                   calendars:calendarArray]; 

// Fetch all events that match the predicate. 
NSArray *events = [self.eventStore eventsMatchingPredicate:predicate]; 

return events; 

}

Verwandte Themen