builttoroam / device_calendar

A cross platform plugin for modifying calendars on the user's device
https://pub.dev/packages/device_calendar
BSD 3-Clause "New" or "Revised" License
270 stars 271 forks source link

iOS 17 PlatformException(401, The user has not allowed this application to modify their calendar(s), null, null) #561

Open FySanta opened 1 month ago

FySanta commented 1 month ago

ios 17.0
var calendarsResult = await _deviceCalendarPlugin.retrieveCalendars() has error PlatformException(401, The user has not allowed this application to modify their calendar(s), null, null)

await _deviceCalendarPlugin.requestPermissions(); await _deviceCalendarPlugin.hasPermissions(); var calendarsResult = await _deviceCalendarPlugin.retrieveCalendars();

31728382804_ pic errorcode:599 errorMessage:Device calendar plugin ran into an issue. Platform specific exception [401], with message :"The user has not allowed this application to modify their calendar(s)", has been thrown.

When getting the fullaccess privileges for a calendar, running await _deviceCalendarPlugin.requestPermissions() gives true after the user grants the privileges, but await _deviceCalendarPlugin.hasPermissions() says is false, and only becomes true after restarting the app.

IVLIVS-III commented 1 month ago

make sure that this line of code await _deviceCalendarPlugin.hasPermissions(); returns true. Otherwise permissions have not been granted.

FySanta commented 1 month ago

确保此行代码await _deviceCalendarPlugin.hasPermissions();返回true。否则权限未授予。

It shows authorized inside the app settings, but await _deviceCalendarPlugin.hasPermissions() return false

FySanta commented 1 month ago

91728439398_ pic

IVLIVS-III commented 1 month ago

That is strange, can you provide a minimum example to reproduce this issue?

FySanta commented 1 month ago

That is strange, can you provide a minimum example to reproduce this issue?

Here's my running order

await _deviceCalendarPlugin.requestPermissions(); 
await _deviceCalendarPlugin.hasPermissions(); 
var calendarsResult = await _deviceCalendarPlugin.retrieveCalendars();

You can check separately the permission status returned by these two lines of code.

await _deviceCalendarPlugin.requestPermissions(); 
await _deviceCalendarPlugin.hasPermissions(); 
achapkey commented 3 weeks ago

Ran into the similar issue. Could not get permission request at all. It even didn't appear in system settings. Worked it around via requesting the permission from permission_handler, but it requires relaunching the app to retrieve the calendar list. Moreover, it reproduces only on 17.0, on 17.2 and higher works like charm (couldn't get my hands on iOS 17.1).

HatsuneMikuV commented 2 weeks ago
private func requestPermissions(completion: @escaping (Bool) -> Void) {
        if hasEventPermissions() {
            completion(true)
            return
        }
        if #available(iOS 17, *) {
            eventStore.requestFullAccessToEvents {
                (accessGranted: Bool, _: Error?) in
                completion(accessGranted)
            }
        } else {
            eventStore.requestAccess(to: .event, completion: {
                (accessGranted: Bool, _: Error?) in
                completion(accessGranted)
            })
        }
    }
    private func requestPermissions(_ result: @escaping FlutterResult) {
        if hasEventPermissions()  {
            result(true)
        }
        eventStore.requestAccess(to: .event, completion: {
            (accessGranted: Bool, _: Error?) in
            result(accessGranted)
        })
    }

https://github.com/builttoroam/device_calendar/blob/8cd4161bc5ece4ebbfb09f009cade8a08946aead/ios/Classes/SwiftDeviceCalendarPlugin.swift#L914

https://github.com/builttoroam/device_calendar/blob/8cd4161bc5ece4ebbfb09f009cade8a08946aead/ios/Classes/SwiftDeviceCalendarPlugin.swift#L941

It should be caused by two methods with the same name