Bug 33338 - EventKit EventStore.RequestAccessAsync always returns true
Summary: EventKit EventStore.RequestAccessAsync always returns true
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 8.10
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-08-24 15:50 UTC by Momm
Modified: 2015-09-03 21:48 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test Project (815.80 KB, application/zip)
2015-09-03 20:54 UTC, Jon Goldberger [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Momm 2015-08-24 15:50:23 UTC
When I call eventStore.RequestAccessAsync it's always returning true, even if the user hasn't granted access, so I need to check if "eventStore.DefaultCalendarForNewEvents" is different than null.

If I call eventStore.RequestAccess, the callback returns correctly.

var response = await eventStore.RequestAccessAsync(EKEntityType.Event);
                bool granted = response.Item1;

                if (granted && eventStore.DefaultCalendarForNewEvents != null)
                {
                    EKEvent newEvent = EKEvent.FromStore(eventStore);
                    newEvent.AddAlarm(EKAlarm.FromDate(date.DateTimeToNSDate()));
                    newEvent.StartDate = date.DateTimeToNSDate();
                    newEvent.EndDate = date.AddMinutes(30).DateTimeToNSDate();
                    newEvent.Title = title;
                    newEvent.Notes = description;
                    newEvent.Calendar = eventStore.DefaultCalendarForNewEvents;

                    NSError error;
                    eventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out error);

                    if (error == null)
                    {
                        return true;
                    }
                }
Comment 1 Jon Goldberger [MSFT] 2015-09-03 20:53:42 UTC
Setting to confirmed as I can reproduce this issue, but I wonder whether using the async method is necessary. Since the "non-async" version pops up an alert it seems it is necessarily asynchronous, which is reinforced by this note in the docs for using EventKit here:
>https://developer.xamarin.com/guides/ios/platform_features/introduction_to_event_kit/#Requesting_Access_to_Calendar_and_Reminder_Data

In that section it says specifically: "Because it raises an alert view, the call is asynchronous, and will call a completion handler passed as an NSAction (or Lambda) to it..." 

So my suggestion would be to just use the RequestAccess call rather than RequestAccessAsync.

In any case, I am attaching a test project based on our Calendars sample with the async call being used instead. 

## Steps to reproduce:

1. Open the attached project and launch it to an iSO device or simulator.

2. Tap "Calendars" at the top of the list.

3. In the alert asking for permission click "Don't Allow"

Expected result: Alert will show up with message "Returned Value - False"

Actual result: Alert shows up with message "Returned Value - True"


## Notes

I tested with XI version  8.13.0.131 
So it would seem that this is not a regression as the bug reporter claims they hit this on version 8.10

#my environment

=== Xamarin Studio ===

Version 5.10 (build 704)
Installation UUID: 964c531b-d928-456b-a9ae-e1f82266b360
Runtime:
	Mono 4.2.0 (explicit/2701b19)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402000207

=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 6.4 (7720)
Build 6E35b

=== Xamarin.Mac ===

Version: 2.3.0.131 (Business Edition)

=== Xamarin.Android ===

Version: 5.1.99.653 (Business Edition)
Android SDK: /Users/apple/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)

SDK Tools Version: 24.3.4
SDK Platform Tools Version: 23
SDK Build Tools Version: 23

Java SDK: /usr
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

=== Xamarin Android Player ===

Version: 0.5.6
Location: /Applications/Xamarin Android Player.app

=== Xamarin.iOS ===

Version: 8.13.0.131 (Business Edition)
Hash: 79f8535
Branch: master
Build date: 2015-08-31 15:32:33-0400

=== Build Information ===

Release ID: 510000704
Git revision: c16e63aeeaa63ea912638f958ae1547905aed4e5
Build date: 2015-08-31 15:47:00-04
Xamarin addins: a7a74af8bcc6bca9a02f34afb66025c0a3fa18cb
Build lane: monodevelop-lion-master

=== Operating System ===

Mac OS X 10.10.5
Darwin Jons-iMac.local 14.5.0 Darwin Kernel Version 14.5.0
    Wed Jul 29 02:26:53 PDT 2015
    root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64
Comment 2 Jon Goldberger [MSFT] 2015-09-03 20:54:34 UTC
Created attachment 12746 [details]
Test Project
Comment 3 Sebastien Pouliot 2015-09-03 21:48:47 UTC
The issue is that the generated async code is checking for an NSError (not just the `bool`) and, in this case, no error is returned. Thanks for the sample.

maccore/master 4637ba2c271e68a57536e7849148c0f9a2d369cb
maccore/cycle6 b6db746de0d91280b8a1d64b003d75b03f2e6a7f