i have a problem to get an calendar entry from Eventstore via eventfromIdentifier. To Save a Event works fine, but when i tryto retrieve a Event from EventStore, it returns null. I checked other Questions here on stackoverflow and no one fix it. I hope you can help.
Function to save calendar entry, works fine. I get the UUID and save it to the local database.
private void createOneCalendarEntry(VorstellungEventArgs e) {
EKEvent newEvent = EKEvent.FromStore(CalendarHelper.Current.EventStore);
newEvent.StartDate = DateHelper.DateTimeToNSDate(e.Vorstellung.Beginn ?? DateTime.Now);
DateTime StartTime = e.Vorstellung.Beginn ?? DateTime.MinValue;
var Duration = e.Vorstellung.Dauer ?? 90;
newEvent.EndDate = DateHelper.DateTimeToNSDate(StartTime.AddMinutes(Duration));
newEvent.Title = e.Vorstellung.PublikationsTitel;
newEvent.Notes = e.Vorstellung.ZeitUndOrtString;
newEvent.Calendar = CalendarHelper.Current.EventStore.DefaultCalendarForNewEvents;
NSError a;
try
{ // Save Note to Calendar to get UUID
CalendarHelper.Current.EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, true, out a);
if (a != null)
{
new UIAlertView("Err Saving Event", a.ToString(), null, "ok", null).Show();
return;
}
else
{ // Test: Show UUID
new UIAlertView(newEvent.UUID, "wurden zum Kalendar hinzugefügt", null, "ok", null).Show();
ViewModel.DataManager.InsertCalID(e.Vorstellung.Id, e.Vorstellung.FilmId, newEvent.UUID);
}
}
catch
{
new UIAlertView("Fehler", "Kalendareinträge wurden nicht erstellt", null, "ok", null).Show();
}
finally
{
}
}
And here comes the function to call the entry and delete them. "ViewModel.DataManager.getCalID(e.Vorstellung.Id, e.Vorstellung.FilmId)" gives me the UUID that a created upside.
private void deleteEventfromCalandar(VorstellungEventArgs e)
{
NSError a;
// Get UUID from local Database an get Event from UUID THIS RETURNS ALWAYS NULL
EKEvent EventToDelete = CalendarHelper.Current.EventStore.EventFromIdentifier(ViewModel.DataManager.getCalID(e.Vorstellung.Id, e.Vorstellung.FilmId));
// Delete current event from calendar
CalendarHelper.Current.EventStore.RemoveEvent(EventToDelete, EKSpan.ThisEvent,true, out a);
new UIAlertView("Erfolg", "Kalendareintrag mit "+EventToDelete.UUID+" wurde gelöscht", null, "ok", null).Show();
}
Here the Eventstore, copied from Xamarin doku
class CalendarHelper
{
public static CalendarHelper Current
{
get { return current; }
}
private static CalendarHelper current;
public EKEventStore EventStore
{
get { return eventStore; }
}
protected EKEventStore eventStore;
static CalendarHelper()
{
current = new CalendarHelper();
}
protected CalendarHelper()
{
eventStore = new EKEventStore();
}
}
And Yes my App have permission to calendar
CalendarHelper.Current.EventStore.RequestAccess(EKEntityType.Event,
(bool granted, NSError e) =>
{
if (granted)
{
}
else
{
new UIAlertView("Access Denied", "user Denied Access to Calendar Data", null, "ok", null).Show();
}
});
I fixed it! The Problem was that i saved the wrong identifier. There are two different identifier,"UUID" and "Eventidentifier". With the Eventidentifier my code just works fine.
ViewModel.DataManager.InsertCalID(e.Vorstellung.Id, e.Vorstellung.FilmId, newEvent.Eventidentifier);
and
new UIAlertView("Erfolg", "Kalendareintrag mit "+EventToDelete.Eventidentifier +" wurde gelöscht", null, "ok", null).Show();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.