Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

[Bug] iOS 17+ Calendar Permissions not working when setting the first time #2105

Closed
mh05 opened this issue Nov 14, 2023 · 9 comments
Closed
Labels
bug Something isn't working

Comments

@mh05
Copy link

mh05 commented Nov 14, 2023

Description

iOS 17 and higher doesn't show any permission popup when requesting Calendar.Write or Calendar.Read for the first time both on (Mai)Permission and via EventStore (Eventstore throwns an error ->

-requestAccessToEntityType:completion: has been deprecated-calling this method is no longer allowed.
Instead, use -requestFullAccessToEventsWithCompletion:, -requestWriteOnlyAccessToEventsWithCompletion:, or -requestFullAccessToRemindersWithCompletion:
)

Steps to Reproduce

  1. Make a new ios application (dotnet 7+)
  2. Add true to project files
  3. Add NSCalendarsUsageDescription description to info.list
  4. Add an button to screen with click event
  5. Start and press on the button

note: When the user declines the permission

Example code: With (maui)permission

    private async Task RequestCalendarPermissions()
   {	
        var permissionWrite = await Permissions.CheckStatusAsync<Permissions.CalendarWrite>();
		var permissionRead = await Permissions.CheckStatusAsync<Permissions.CalendarRead>();

		
        if (permissionWrite != PermissionStatus.Granted)
        {
	   BeginInvokeOnMainThread(() => Permissions.RequestAsync<Permissions.CalendarWrite>()); 	
        }		

        if (permissionRead != PermissionStatus.Granted)
        {
           BeginInvokeOnMainThread(() => Permissions.RequestAsync<Permissions.CalendarRead>());
        }        
    }

Example code without (maui)Permission

private async Task RequestEventPermission()
	{
        var store = new EKEventStore();
        var setPermission = await store.RequestAccessAsync(EKEntityType.Event);
        //results in error from ios
      
	}

Expected Behavior

1:
Permission popup for with
"name app" Would like to Access Your Calander
description from info.plist

2:
Settings -> Privancy & Security -> Calendars -> "App name" toggle switch on (at least when you accept it)

3:
Settings -> "App name" -> Allow "app name" To Acces -> Calendars.

Actual Behavior

Apps doesn't show any popup

Basic Information

  • Version with issue:
  • Last known good version: till ios 17
  • IDE: Vs for mac
  • Platform Target Frameworks:
    • iOS: 17.0 (simulator and device)
    • Android: N/A
    • UWP: N/A
  • Android Support Library Version:
  • Nuget Packages:
  • MAUI Essentials
  • Affected Devices:
@mh05 mh05 added the bug Something isn't working label Nov 14, 2023
@hlubik
Copy link

hlubik commented Nov 18, 2023

Xamarin.Forms too. Latest Version of all SDKs and Frameworks. Calendar Access is very important

@vikher
Copy link

vikher commented Nov 21, 2023

I wanted to reach out to let you know that I'm still encountering the same challenge with the iOS 17 Calendar permissions. Despite ensuring the necessary configurations and code adjustments as discussed previously, the permission prompts for Calendar.Write or Calendar.Read are still not displaying as expected

@john26l
Copy link

john26l commented Nov 21, 2023

Xamarin form App, just upgraded to iOS 17, Calendar permission no longer working, but other permission such as contact write still working, can any one have a clue and please advise, thanks lot

@mh05
Copy link
Author

mh05 commented Nov 24, 2023

@john26l In dotnet 8 you can use the solution of Plugin.Maui.CaledarStore
https://github.com/jfversluis/Plugin.Maui.CalendarStore/pull/46/files#

@hlubik
Copy link

hlubik commented Nov 24, 2023

Is there no solution for Xamarin.Forms with .Net Standard 2.0 ??

@jfversluis
Copy link
Member

The solution could be along the same lines as the link posted above. I'll see what I can do to also add that to Xamarin.Essentials.

@hlubik
Copy link

hlubik commented Nov 30, 2023

Hi Gerald, good news, and better, if you (or someone else) could it ASAP, or a workaround with Dependency injection?
I need this very urgent.
Thanks

@gering
Copy link

gering commented Dec 7, 2023

Since the PR above is somehow stuck, I did try to resolve this for myself and was able to do so with a bit of effort.

The main issue is, that the iOS-SDK bundled with Xamarin only supports the iOS 16 bindings and does not contain the ones from 17. Unfortunately, Apple decided to deprecaterequestAccessToEntityType of EKEventStore permission requests and make them fail at the same time, instead of adding a fallback implementation, that would use requestFullAccessToEventsWithCompletion under the hood.

Anyway, first approach was to simply call the new requestFullAccessToEventsWithCompletion with Obj-c message send via Selector directly from C#, but that failed, because I was not able to provide the parameter for the callback correctly.

But, creating a small static (obj-c) lib, which wraps the missing calls to EKEventStore + creating the bindings for C#, just works fine. Remember to build a fat lib, in order to also support iOS simulator.

here you go → https://github.com/gering/EventKitPermissionsWrapper

Use make to build the static lib

@jfversluis
Copy link
Member

jfversluis commented Dec 7, 2023

Thank you @gering! Yeah I was wondering about that. I do see the bindings come up on my machine, but I guess that might be some weird mixup between the .NET MAUI and Xamarin bits, because indeed there is Xcode 15 support but no new APIs so I guess we won't be able to implement this in Xamarin.Essentials anymore.

Thank you for this workaround!

Closing this one as we can't make this work on the Xamarin side because while Xcode 15 is supported for Xamarin, no new APIs have been added. Only the ability to build against Xcode 15 and prolong the Xamarin lifespan a little.

If you really need this, use the workaround above or migrate to .NET MAUI.

@jfversluis jfversluis closed this as not planned Won't fix, can't repro, duplicate, stale Dec 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants