dpa99c / cordova-diagnostic-plugin

Cordova/Phonegap plugin to manage device settings
535 stars 352 forks source link

requestCalendarAuthorization() always returns DENIED_ALWAYS #512

Open yudateNoriyuki opened 4 months ago

yudateNoriyuki commented 4 months ago

Bug report

CHECKLIST

Current behavior:

  1. Call requestCalendarAuthorization() on iOS 17.
  2. OS dialog does not appear.
  3. The successCallback consistently returns DENIED_ALWAYS.

Expected behavior:

Before granting calendar permission, the OS dialog should appear, and the response in the successCallback should vary based on the user's selection.

Steps to reproduce:

Same as described above.

Screenshots

Environment information

Runtime issue

aks7665 commented 3 months ago

I am also facing the same problem with following versions:

Device details iPhone14

OS details iOS17.2.1

@yudateNoriyuki Have you found any solution?

yudateNoriyuki commented 3 months ago

@aks7665 Yes, I was able to solve it using ChatGPT, although not perfectly. I resolved it by modifying the following part of src/ios/Diagnostic_Calendar.m:

Before

[self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
    [diagnostic logDebug:[NSString stringWithFormat:@"Access request to calendar events: %d", granted]];
    [diagnostic sendPluginResultBool:granted:command];
}];

After

if (@available(iOS 17, *)) {
    [self.eventStore requestFullAccessToEventsWithCompletion:^(BOOL granted, NSError *error) {
        [diagnostic logDebug:[NSString stringWithFormat:@"Access request to calendar events: %d", granted]];
        [diagnostic sendPluginResultBool:granted:command];
    }];
} else {
    [self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
        [diagnostic logDebug:[NSString stringWithFormat:@"Access request to calendar events: %d", granted]];
        [diagnostic sendPluginResultBool:granted:command];
    }];
}

This allows requesting full access to calendar permissions. However, please note that if you're using https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin, this modification alone won't enable you to add events to the calendar. Be cautious about that.