1

In my Application i need to attach(show iphone inbuilt calender) in-built iphone calendar on the UIButton action. More, The text from my UIViewControllers UILabel, I need attach that text in iphones in built calendar as reminder, where user is free to select date according his need. I had found like EventKIt framework may be useful to me, But i am not sure. And i am also not familiar with EventKit framework.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Vishal Sharma
  • 1,733
  • 2
  • 12
  • 32

1 Answers1

1

Just Use this example with EventKit framwork.

    -(IBAction)buttonAction:(id)sender
    {

        EKEventStore *eventStore = [[EKEventStore alloc] init];
        EKEventStore *eventStore = [[[EKEventStore alloc] init] autorelease];
        if([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])                {
            // iOS 6 and later
            [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
                if (granted){
                    //---- codes here when user allow your app to access theirs' calendar.
                    [self performCalendarActivity:eventStore];
                }else
                {
                    //----- codes here when user NOT allow your app to access the calendar.
                }
            }];
        }
         else {
                    //---- codes here for IOS < 6.0.
                    [self performCalendarActivity:eventStore];
        }           

    }

-(void)performCalendarActivity:(EKEventStore *)eventStore 

{
    EKEvent *event  = [EKEvent eventWithEventStore:eventStore];
    event.title     = @"EVENT TITLE";
event.startDate = [[NSDate alloc] init];
event.endDate   = [[NSDate alloc] initWithTimeInterval:600  sinceDate:event.startDate];
    [event setCalendar:[eventStore defaultCalendarForNewEvents]];
            NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
}

Don't forget to import #import <EventKit/EventKit.h> to your view controller.

Mani
  • 17,549
  • 13
  • 79
  • 100
  • thanx for your help. i will tell you after use it. – Vishal Sharma Feb 05 '14 at 06:26
  • log show me below error: Error Domain=EKCADErrorDomain Code=1013 "The operation couldn’t be completed. (EKCADErrorDomain error 1013.)" – Vishal Sharma Feb 05 '14 at 06:38
  • Reason is : Ios app wont be able to get any data from the Calendar on the iOS6 system if you don’t call the – requestAccessToEntityType:completion: function to prompt a dialog to ask your users to grant access to your app to access the Calendar/Reminder... see this link http://stackoverflow.com/questions/12454324/defaultcalendarfornewevents-failed – Mani Feb 05 '14 at 06:40
  • I did, very first time , it shows a pop up msg like "allow app to acces your calender", i had allow it,but calender is not shown on my screen, which is fundamental need for my app. – Vishal Sharma Feb 05 '14 at 06:57
  • I think, You are done. After you click allow button, Your created event automatically added to your calendar, see your calendar app. You have added event with "Event title"... It won't show calendar app.. – Mani Feb 05 '14 at 06:59
  • Actually, Basic need in my app is "user can set reminder on calendar, on date which he/she like". so, in our assumption how we do stuff with date? – Vishal Sharma Feb 05 '14 at 07:05
  • @yourwish If you want to select date, Use date picker. see this link http://stackoverflow.com/questions/12740423/how-to-display-picker-view-in-mm-dd-yy-format-in-ios-5-1. Finally set event date from selected date from date picker. – Mani Feb 05 '14 at 07:08
  • great help, but if actual default calendar will pop up then its pretty good for me. thanx – Vishal Sharma Feb 05 '14 at 07:18
  • i just have 13 reputation, for vote up itz need 15! u vote up my que then i am able to vote up your ans – Vishal Sharma Feb 05 '14 at 07:20
  • if it is posiible to attach default iphone calendar then please refer me. – Vishal Sharma Feb 05 '14 at 07:21
  • @yourwish I think you cann't popup default iPhone calendar from your app. But you can switch to calendar app. – Mani Feb 05 '14 at 07:23