I m working iOS calendar events in my app.
I dont want to add duplicate event i.e if event is not modified i dont want to add it.
I m using saveEvent:event span:EKSpanThisEvent error:&error method from EkEventStore. As per documentation, this method returns NO if event is already in store.
But m getting duplicate events also in Calendar. Please suggest me something if m doing wrong anything.
Thanks.
Related
I've been using EventKit for years in my app (since macOS 10.10) but it's having an odd problem in Mojave.
Previously once I received an EKEventStoreChangedNotification I could query for changed reminders with this:
NSPredicate *predicate = [self.eventStore predicateForRemindersInCalendars:#[self.taskCalendar]];
[self.eventStore fetchRemindersMatchingPredicate:predicate completion:^(NSArray *reminders) {
self.allFetchedTasks = reminders;
}];
Worked like champ. Setting a breakpoint within that block, I could switch to Reminders, change the task title, instantly pop back in the debugger and the reminders array would have the change (via "po [reminders.firstObject title]").
However, now in Mojave the fetch appears to return old information. I get thrown back in the debugger as soon as I change the task title in Reminders but the reminders array still contains the old info. That is, [reminders.firstObject title] is still showing the original title not the title as it exists currently in Reminders. I can continue to change the title in Reminders and each time I'm brought back into the debugger and I still see the original title.
I also attempted to use calendarItemsWithExternalIdentifier but it also returns the original value.
If I relaunch my app then it grabs the latest info but, again, subsequent fetches due to change notifications return the original value.
It doesn't look like Mojave's EventKit has any new caching I can control. Is there something else I'm missing? Do I need to reconstruct my self.eventStore each time now?
This has been fixed in Apple's macOS 10.14.4 Beta 3 release.
I run in the situation that at least local calendars of type EKCalendarTypeLocal are listed by EKEventStore but arent't shown and can not be selected in the calendar app on iOS.
if ([eventStore respondsToSelector:#selector(calendarsForEntityType:)]) cals = [eventStore calendarsForEntityType:EKEntityTypeEvent];
else cals = eventStore.calendars;
I found out that it has probably something to do with iCloud Accessing programmatically created calendar on iOS device.
I also created a local calendar successfully and could add events to it. This created calendar was not listed by EKEventStore but I get it with its identifier:
aCal = [eventStore calendarWithIdentifier:calId];
After I removed the iCloud account in the testing device all local calendars are shown also my own created. Is there any possibility to check if local calendars are hidden? So I can wrote an info text or hide them as well.
Have u solved?
Anyway, i'll try to answer.
As i understand iCloud don't let local calendars to be shown. If u turn of iCloud and then lead him back to on u will see a message like "Would u like to add your local calendar to iCloud?", so ... if the problem is just see the calendars in iCloud, extract your EKCalendar and change source in a EKSourceTypeCalDAV instead than EKSourceTypeLocal ... should be ok
Im trying to set the availability of an event i import into the iphone calendar with my app. Im using this code:
[event1 setAvailability:EKEventAvailabilityFree];
When i sync my iphone to my iCal i check the availability of the event, and it says "Busy". Xcode do ask for an integer, but there is none for the free option. I get no errors when i run this code, can someone please help figure out whats wrong.
The problem is probably that the event's calendar hasn't been set. When the calendar is not set, the event doesn't know if it's valid to set availability (not all calendars support availability).
Try the following:
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = subject;
event.calendar = [eventStore defaultCalendarForNewEvents];
if (event.availability != EKEventAvailabilityNotSupported) {
event.availability = EKEventAvailabilityFree;
}
Further to David Hunt's answer it would appear that you need to set the calendar before you set the availability in your code. The sequence matters.
E.g.
event.calendar = //calendar object
event.availability = //availability typedef
Did you save the event back to the event store that contains it? See the saveEvent:span:error: message in the EKEventStore class reference.
is it possible for my app to programatically add events (with permission from the user) to the iphones calendar?
cheers
w://
It's available in the iPhone 4 SDK, so in Monotouch. Take a look at EKEventStore and EKEvent. Here's the Apple docs.
Here's an example from a snippets page I keep:
public void CalendarEvents()
{
EKEventStore store = new EKEventStore();
EKCalendar calendar = store.DefaultCalendarForNewEvents;
// Query the event
if (calendar != null)
{
// Searches for every event in the next year
NSPredicate predicate = store.PredicateForEvents(NSDate.Now,DateTime.Now.AddDays(360),new EKCalendar[] {calendar});
store.EnumerateEvents(predicate, delegate(EKEvent currentEvent, ref bool stop)
{
// Perform your check for an event type
});
// Add a new event
EKEvent newEvent = EKEvent.FromStore(store);
newEvent.Title = "Lunch at McDonalds";
newEvent.Calendar = calendar;
newEvent.StartDate = DateTime.Now.Today;
newEvent.EndDate = DateTime.Now.Today.AddDays(1);
newEvent.Availability = EKEventAvailability.Free;
store.SaveEvent(newEvent, EKSpan.ThisEvent, new IntPtr());
}
}
A lateral thinking way around this is to consider creating an ICS file, then creating an email (which can be done programmatically) and then send it to the user or whomever they want. This is how I'm getting around this issue in my code. The beauty of it is it also doesn't create the sense in the user that your application is going to manage the dates, i.e. if they change something in your application that you'll cancel and rebook things on the fly.
It's not possible in the official iPhone API, so I doubt it's possible via mono touch.
Not directly possible with the SDK. You might try getting the user to subscribe to an online calendar published from your server, then upload events to that, but you'll probably run into all kinds of syncing issues.
I would like to know whether we can create a calendar using NSCalender and show it in our dedicated application. We can create a NSCalender object by
****NSCalendar *japaneseCalendar = [[NSCalendar alloc] initWithCalendarIdentifier : NSJapaneseCalendar];****
But how can we show this calender in out application. Is there any way to show the default calander in our application when a user click a button.
Please please guide me, i am hanging here for last few days.
Thank You
Rahul
NSCalendar has nothing to with the Calendar app on the iPhone, it's simply a class used to represent a calendar for whatever reason you need one.
I'm not sure that this can be done on the iPhone from within an app.
-
After re-reading your question, I think I misunderstood what you were asking.
If you want to display some kind of calendar view within the app using that particular calendar, you'll have to create you own view and draw the calendar into it.
You may be able to find some code on the internet to accomplish this already.