protected override void RequestAccess() { eventStore.RequestAccess(type, (granted, accessError) => { string text = string.Format("Access {0}", granted ? "allowed" : "denied"); InvokeOnMainThread(() => AccessStatus.Text = text); }); }
public void SetReminder(string title) { EventKitUI.EKEventEditViewController eventController = new EventKitUI.EKEventEditViewController(); eventStore = new EKEventStore(); eventStore.RequestAccess(EKEntityType.Reminder, (bool granted, NSError i) => { if (granted) { accessGranted = true; } else { accessGranted = false; } }); eventController.EventStore = eventStore; EKReminder reminder = EKReminder.Create(eventController.EventStore); reminder.Title = title; reminder.Calendar = eventController.EventStore.DefaultCalendarForNewReminders; // save the reminder NSError e; eventController.EventStore.SaveReminder(reminder, true, out e); }
public Task <bool> AddReminderAsync(string id, CalendarEvent calEvent) { bool success = true; EventStore.RequestAccess( EKEntityType.Event, (granted, e) => { if (granted) { var newEvent = EKEvent.FromStore(EventStore); newEvent.AddAlarm(EKAlarm.FromDate(DateTimeToNSDate(calEvent.Start.AddMinutes(-15)))); newEvent.StartDate = DateTimeToNSDate(calEvent.Start); newEvent.EndDate = DateTimeToNSDate(calEvent.End); newEvent.Title = calEvent.Name; newEvent.Notes = calEvent.Description; newEvent.Location = calEvent.Location; newEvent.AllDay = calEvent.AllDay; newEvent.Calendar = EventStore.DefaultCalendarForNewEvents; } else { this.contentDialogService.Alert("Access Denied", "User Denied Access to Calendar Data"); success = false; } }); return(Task.FromResult(success)); }
public Task RequestAccess() { var tcs = new TaskCompletionSource <object> (); eventStore.RequestAccess(type, (granted, accessError) => tcs.SetResult(null)); return(tcs.Task); }
void ShowActualEventPermissionAlert(ClusterEventAuthorizationType eventType) { EKEventStore aStore = new EKEventStore(); aStore.RequestAccess(EKEquivalentEventType(eventType), delegate { FireEventPermissionCompletionHandler(eventType); }); }
public void RequestEventStoreAccess(EKEntityType type) { if (eventStore == null) { eventStore = new EKEventStore(); } eventStore.RequestAccess(type, delegate(bool granted, NSError error) { ShowAlert(type == EKEntityType.Event ? DataClass.Calendars : DataClass.Reminders, granted ? "granted" : "denied"); }); }
public PNVModel () { EventStore = new EKEventStore (); EventStore.RequestAccess(EKEntityType.Event, delegate (bool arg1, NSError arg2) { if (arg2 != null) { Console.WriteLine (arg2.ToString ()); } }); SelectedCalendar = EventStore.DefaultCalendarForNewEvents; }
public PNVModel() { EventStore = new EKEventStore(); EventStore.RequestAccess(EKEntityType.Event, delegate(bool arg1, NSError arg2) { if (arg2 != null) { Console.WriteLine(arg2.ToString()); } }); SelectedCalendar = EventStore.DefaultCalendarForNewEvents; }
// Chequeo de permisos para acceder a calendario en iOS private void ChequearPermiso() { eventStore.RequestAccess(EKEntityType.Event, (bool granted, NSError error) => { if (!granted) { permisoOtorgado = false; } else { permisoOtorgado = true; } }); }
public void AddEvent(string Titulo, string Lugar, DateTime Inicio, DateTime Termina, string Descripcion) { try { EKEventStore evStore = new EKEventStore(); evStore.RequestAccess(EKEntityType.Event, (bool granted, NSError e) => { if (!granted) { new UIAlertView("Acceso denegado", "El usuario no permite acceso al calendario", null, "ok", null).Show(); } }); EKCalendar calendar = evStore.DefaultCalendarForNewEvents; NSPredicate evPredicate = evStore.PredicateForEvents(Inicio, Termina, evStore.GetCalendars(EKEntityType.Event)); bool encontrado = false; evStore.EnumerateEvents(evPredicate, delegate(EKEvent calEvent, ref bool stop) { if (calEvent.Title == Titulo) { encontrado = true; } }); if (encontrado) { new UIAlertView("Evento", "El evento ya existe en el calendario", null, "ok", null).Show(); } else { EKEvent newEvent = EKEvent.FromStore(evStore); newEvent.Title = Titulo; newEvent.Notes = Descripcion; newEvent.Calendar = calendar; newEvent.StartDate = Inicio; newEvent.EndDate = Termina; newEvent.Location = Lugar; var error = new NSError(new NSString(""), 0); evStore.SaveEvent(newEvent, EKSpan.ThisEvent, out error); if (error.LocalizedDescription != "") { new UIAlertView("Evento", "Hubo un problema al agregar el evento " + error.LocalizedDescription, null, "ok", null).Show(); } else { new UIAlertView("Evento", "El evento se agregó a su calendario", null, "ok", null).Show(); } } } catch (Exception) { new UIAlertView("Evento", "Hubo un problema al agregar el evento", null, "ok", null).Show(); } }
public void requestAccess() { eventStore = new EKEventStore(); eventStore.RequestAccess(EKEntityType.Event, (bool granted, NSError e) => { if (granted) { accessGranted = true; } else { accessGranted = false; } }); }
public void CreateService() { if (eventStore == null) { eventStore = new EKEventStore(); bool valueSet = false; eventStore.RequestAccess(EKEntityType.Reminder, (granted, err) => { available = granted; valueSet = true; }); // it's probably bad to busy-wait here, but the permission to use this might // not be quite there yet. Probably better if CreateService was async maybe? while (!valueSet) { } } }
public void CreateCalendarEntry(LocalCalendarEvent localCalendarEvent) { eventStore.RequestAccess(EKEntityType.Event, (bool granted, NSError e) => { if (granted) { UIApplication.SharedApplication.InvokeOnMainThread(() => { EventKitUI.EKEventEditViewController eventController = new EventKitUI.EKEventEditViewController(); eventController.EventStore = eventStore; // wire up a delegate to handle events from the controller var eventControllerDelegate = new CreateEventEditViewDelegate(eventController, eventStore); eventController.EditViewDelegate = eventControllerDelegate; EKEvent newEvent = EKEvent.FromStore(eventStore); newEvent.StartDate = (NSDate)(DateTime.SpecifyKind(localCalendarEvent.StartDate, DateTimeKind.Local)); if (localCalendarEvent.EndDate.HasValue) { newEvent.EndDate = (NSDate)(DateTime.SpecifyKind(localCalendarEvent.EndDate.Value, DateTimeKind.Local)); } newEvent.Title = localCalendarEvent.Subject; newEvent.Notes = localCalendarEvent.Description; newEvent.Location = localCalendarEvent.Location; if (localCalendarEvent.ReminderDate.HasValue) { newEvent.AddAlarm(EKAlarm.FromDate((NSDate)(DateTime.SpecifyKind(localCalendarEvent.ReminderDate.Value, DateTimeKind.Local)))); } eventController.Event = newEvent; // show the event controller UIApplication.SharedApplication.Windows[0].RootViewController.PresentViewController(eventController, true, null); }); } else { new UIAlertView("Access Denied", "User Denied Access to Calendar Data", null, "ok", null).Show(); } }); }
public void CreateService() { if (eventStore == null) { eventStore = new EKEventStore(); eventStore.RequestAccess(EKEntityType.Reminder, (bool granted, NSError e) => { if (granted) { accessGranted = true; } else { accessGranted = false; } }); } }
public void AddEvent(string Titulo, string Lugar, DateTime Inicio, DateTime Termina, string Descripcion) { try { EKEventStore evStore = new EKEventStore(); evStore.RequestAccess(EKEntityType.Event, (bool granted, NSError e) => { if (!granted) new UIAlertView("Acceso denegado", "El usuario no permite acceso al calendario", null, "ok", null).Show(); }); EKCalendar calendar = evStore.DefaultCalendarForNewEvents; NSPredicate evPredicate = evStore.PredicateForEvents(Inicio, Termina, evStore.GetCalendars(EKEntityType.Event)); bool encontrado = false; evStore.EnumerateEvents(evPredicate, delegate(EKEvent calEvent, ref bool stop) { if (calEvent.Title == Titulo) encontrado = true; }); if (encontrado) { new UIAlertView("Evento", "El evento ya existe en el calendario", null, "ok", null).Show(); } else { EKEvent newEvent = EKEvent.FromStore(evStore); newEvent.Title = Titulo; newEvent.Notes = Descripcion; newEvent.Calendar = calendar; newEvent.StartDate = Inicio; newEvent.EndDate = Termina; newEvent.Location = Lugar; var error = new NSError(new NSString(""), 0); evStore.SaveEvent(newEvent, EKSpan.ThisEvent, out error); if(error.LocalizedDescription!="") new UIAlertView("Evento", "Hubo un problema al agregar el evento " + error.LocalizedDescription, null, "ok", null).Show(); else new UIAlertView("Evento", "El evento se agregó a su calendario", null, "ok", null).Show(); } } catch (Exception) { new UIAlertView("Evento", "Hubo un problema al agregar el evento", null, "ok", null).Show(); } }
private Task <bool> ASkForPermissionsAsync() { TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>(); eventsStore.RequestAccess(EKEntityType.Event, (bool granted, NSError error) => { if (!granted) { var alert = UIAlertController.Create("Acceso denegado", "Acceso al calendario denegado por el usuario", UIAlertControllerStyle.Alert); UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(alert, true, null); } else { appCalendar = eventsStore.Calendars.Where(c => c.Title.ToLowerInvariant().Equals(calendarTitle.ToLowerInvariant())).FirstOrDefault(); } tcs.SetResult(granted); }); return(tcs.Task); }
public void AddEventToCalendar(CultureInfo ci, DateTime from, DateTime until, string name, string location) { try { EventStore.RequestAccess(EKEntityType.Event, (granted, e) => { if (granted) { UIApplication.SharedApplication.InvokeOnMainThread(() => { var eventController = new EKEventEditViewController { EventStore = EventStore }; var eventControllerDelegate = new CreateEventEditViewDelegate(eventController); eventController.EditViewDelegate = eventControllerDelegate; var newEvent = EKEvent.FromStore(EventStore); newEvent.StartDate = DateTimeToNsDate(from); newEvent.EndDate = DateTimeToNsDate(until); newEvent.AllDay = true; newEvent.Location = location; newEvent.Title = name; newEvent.Calendar = EventStore.DefaultCalendarForNewEvents; eventController.Event = newEvent; UIApplication.SharedApplication.Windows[0].RootViewController .PresentViewController(eventController, true, null); }); } }); } catch (Exception) { // shht } }
public bool AddToCalendar(CalendarModel calendarModel) { //var granted = EventStore.RequestAccessAsync(EKEntityType.Event); EventStore.RequestAccess(EKEntityType.Event, (bool granted, NSError e) => { if (granted) { EKEvent newEvent = EKEvent.FromStore(EventStore); newEvent.Title = calendarModel.Title; newEvent.Notes = calendarModel.Description; newEvent.StartDate = (NSDate)calendarModel.Start; newEvent.EndDate = (NSDate)calendarModel.End; newEvent.Location = calendarModel.Location; newEvent.Calendar = EventStore.DefaultCalendarForNewEvents; EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e); return; } new UIAlertView("Access Denied,", "User Denied Access to Calendar Data", null, "ok", null).Show(); Debug.WriteLine(e); }); return(true); }
public static EKEvent[] FetchEvents(DateTime startDate, DateTime endDate) { // Create the predicate. Pass it the default calendar. //Util.WriteLine ("Getting Calendars"); EKEventStore store = new EKEventStore(); store.RequestAccess(EKEntityType.Event, (bool granted, NSError e) => { if (granted) { #if DEBUG Console.WriteLine("Access Granted!"); #endif //Do add events calendars and any calendar stuff here } else { new UIAlertView("Access Denied", "User Denied Access to Calendar Data", null, "ok", null).Show(); } } ); var calendarArray = store.Calendars; //Util.WriteLine ("Predicate"); //Convert to NSDate NSDate nstartDate = Util.DateTimeToNSDate(startDate); NSDate nendDate = Util.DateTimeToNSDate(endDate); NSPredicate predicate = store.PredicateForEvents(nstartDate, nendDate, calendarArray); //Util.WriteLine ("Fetching Events"); // Fetch all events that match the predicate. var eventsArray = store.EventsMatching(predicate); //Util.WriteLine ("Returning results"); if (eventsArray == null) { eventsArray = new List <EKEvent> ().ToArray(); } return(eventsArray); }
/// <summary> /// Creates new reminder about medicine /// </summary> /// <param name="Name">Name of medicine</param> /// <param name="time">Time of taking medicine</param> public void AddReminder(string Name, NSDate time) { /* * EKReminder reminder = EKReminder.Create(eventStore); * reminder.Title = Name; * NSError e = new NSError(); * EKAlarm timeToRing = new EKAlarm(); * timeToRing.AbsoluteDate = time; * reminder.Calendar = eventStore.DefaultCalendarForNewReminders; * reminder.AddAlarm(timeToRing); * //reminder.Calendar = eventStore.DefaultCalendarForNewReminders; * eventStore.SaveReminder(reminder, true, out e); */ eventStore.RequestAccess(EKEntityType.Event, (bool granted, NSError e) => { if (granted) { EKEvent newEvent = EKEvent.FromStore(eventStore); newEvent.StartDate = (NSDate)DateTime.Now; newEvent.EndDate = (NSDate)DateTime.Now.AddMinutes(5); newEvent.Title = Name; newEvent.Calendar = eventStore.DefaultCalendarForNewEvents; eventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e); } //do something here else { var okAlertController = UIAlertController.Create("Error", "Application doesnt have permission for calendar.", UIAlertControllerStyle.Alert); okAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(okAlertController, true, null); } }); }
public void RequestEventStoreAccess(EKEntityType type) { eventStore.RequestAccess(type, delegate(bool granted, NSError error) { InvokeOnMainThread(() => accessStatus.Text = "Access " + (granted ? "allowed" : "denied")); }); }
public static EKEvent[] FetchEvents(DateTime startDate, DateTime endDate) { // Create the predicate. Pass it the default calendar. //Util.WriteLine ("Getting Calendars"); EKEventStore store = new EKEventStore (); store.RequestAccess (EKEntityType.Event, (bool granted, NSError e) => { if (granted) { #if DEBUG Console.WriteLine("Access Granted!"); #endif //Do add events calendars and any calendar stuff here } else new UIAlertView ( "Access Denied", "User Denied Access to Calendar Data", null, "ok", null).Show (); } ); var calendarArray = store.Calendars; //Util.WriteLine ("Predicate"); //Convert to NSDate NSDate nstartDate = startDate.DateTimeToNSDate(); NSDate nendDate = endDate.DateTimeToNSDate(); NSPredicate predicate = store.PredicateForEvents (nstartDate, nendDate, calendarArray); //Util.WriteLine ("Fetching Events"); // Fetch all events that match the predicate. var eventsArray = store.EventsMatching (predicate); //Util.WriteLine ("Returning results"); if (eventsArray == null) { eventsArray = new List<EKEvent> ().ToArray (); } return eventsArray; }
public async void AddEventToCalender(object sender, EventArgs e) { try { var store = new EKEventStore(); if (EKEventStore.GetAuthorizationStatus(EKEntityType.Reminder) == EKAuthorizationStatus.Authorized) { if (EKEventStore.GetAuthorizationStatus(EKEntityType.Event) == EKAuthorizationStatus.Authorized) { NSDate startDate = ConvertDateTimeToNSDate(BaseFunctions.GetDateTimeFull(App.reminderEvent.eventStartDate + " " + App.reminderEvent.eventStartTime)); NSDate endDate = ConvertDateTimeToNSDate(BaseFunctions.GetDateTimeFull(App.reminderEvent.eventEndDate + " " + App.reminderEvent.eventEndTime)); NSPredicate query = store.PredicateForEvents(startDate, endDate, null); EKCalendarItem[] events = store.EventsMatching(query); bool exists = false; for (int i = 0; i < events.Length; i++) { if (events[i].Title == App.reminderEvent.eventName) { exists = true; } } if (!exists) { EKEvent eEvent = EKEvent.FromStore(store); eEvent.AddAlarm(EKAlarm.FromDate(ConvertDateTimeToNSDate(BaseFunctions.GetDateTimeFull(App.reminderEvent.eventStartDate + " " + App.reminderEvent.eventStartTime)))); eEvent.StartDate = startDate; eEvent.EndDate = endDate; eEvent.Title = App.reminderEvent.eventName; eEvent.TimeZone = new NSTimeZone("UTC"); eEvent.Location = App.reminderEvent.eventAddress; eEvent.Notes = App.reminderEvent.eventDescription; eEvent.Calendar = store.DefaultCalendarForNewEvents; NSError eventError; store.SaveEvent(eEvent, EKSpan.ThisEvent, out eventError); EKReminder reminder = EKReminder.Create(store); reminder.Title = App.reminderEvent.eventName; reminder.AddAlarm(EKAlarm.FromDate(ConvertDateTimeToNSDate(BaseFunctions.GetDateTimeFull(App.reminderEvent.eventStartDate + " " + App.reminderEvent.eventStartTime)))); reminder.TimeZone = new NSTimeZone("UTC"); reminder.Calendar = store.DefaultCalendarForNewEvents; await App.Current.MainPage.DisplayAlert("Alert", "This event is added to your calender", "Ok"); } else { await App.Current.MainPage.DisplayAlert("Alert", "This event is already added to your calender", "Ok"); } } else { store.RequestAccess(EKEntityType.Event, StoreAcceptRequest); } } else { store.RequestAccess(EKEntityType.Reminder, StoreAcceptRequest); } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } }
void ShowActualEventPermissionAlert(ClusterEventAuthorizationType eventType) { EKEventStore aStore = new EKEventStore (); aStore.RequestAccess (EKEquivalentEventType (eventType), delegate { FireEventPermissionCompletionHandler (eventType); }); }