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
267 stars 267 forks source link

iOS 17 PlatformException(500, That account does not allow calendars to be added or removed., null, null) #490

Open Allenxuxu opened 1 year ago

Allenxuxu commented 1 year ago

Describe the bug In iOS17 , it will print

PlatformException(500, That account does not allow calendars to be added or removed., null, null)

Flutter doctor [✓] Flutter (Channel stable, 3.10.1, on macOS 13.4.1 22F82 darwin-x64, locale zh-Hans-CN) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1) [✓] Xcode - develop for iOS and macOS (Xcode 14.3) [✓] Chrome - develop for the web [✓] Android Studio (version 2022.1) [✓] IntelliJ IDEA Ultimate Edition (version 2022.2.3) [✓] IntelliJ IDEA Ultimate Edition (version 2022.2.3) [✓] Connected device (3 available) [✓] Network resources

• No issues found!

IVLIVS-III commented 1 year ago

@Allenxuxu please add steps to reproduce your issue. What didi you do that caused this exception? What did you expect should have happened instead if everything worked correctly?

Allenxuxu commented 1 year ago

@Allenxuxu please add steps to reproduce your issue. What didi you do that caused this exception? What did you expect should have happened instead if everything worked correctly?

In iOS17, if you call createOrUpdateEvent , it can't work and print:

PlatformException(500, That account does not allow calendars to be added or removed., null, null)

In other version iOS, it works well.

thomassth commented 1 year ago

is there some API or permission changes to ios17?

IVLIVS-III commented 1 year ago

is there some API or permission changes to ios17?

not according to Apple's own documentation

Bildschirmfoto 2023-06-30 um 21 28 47 Bildschirmfoto 2023-06-30 um 21 31 03 Bildschirmfoto 2023-06-30 um 21 31 24
Allenxuxu commented 1 year ago

is there some API or permission changes to ios17?

not according to Apple's own documentation

Bildschirmfoto 2023-06-30 um 21 28 47 Bildschirmfoto 2023-06-30 um 21 31 03 Bildschirmfoto 2023-06-30 um 21 31 24

I feel weird too, but I'm not very good at swift. I think you can download a iOS 17 emulator and try it out, it's 100% reproduced in my case.

kalismeras61 commented 1 year ago

I have same issue...

kalismeras61 commented 1 year ago

@IVLIVS-III i think it is related to below.

https://developer.apple.com/documentation/technotes/tn3152-migrating-to-the-latest-calendar-access-levels

manylittlestorms commented 1 year ago

@IVLIVS-III i think it is related to below.

https://developer.apple.com/documentation/technotes/tn3152-migrating-to-the-latest-calendar-access-levels

@builttoroamadmin This seems very important. We probably need an update.

kalismeras61 commented 1 year ago

@IVLIVS-III or @builttoroamadmin is it possible to help here ?

Allenxuxu commented 1 year ago

@IVLIVS-III i think it is related to below. https://developer.apple.com/documentation/technotes/tn3152-migrating-to-the-latest-calendar-access-levels

@builttoroamadmin This seems very important. We probably need an update.

I tested it, as long as I give the APP full permissions in the settings (full access to events), I can use it normally. This package just request write-only access to events now. Therefore, I think we should only need to update the package code, just request full access to events permissions

kalismeras61 commented 1 year ago

any update on this ?

junqi commented 1 year ago

@kalismeras61 I submitted a workaround PR (https://github.com/builttoroam/device_calendar/pull/497)

You can try it by the following steps.

  1. modify pubspec.yaml as follows.
    device_calendar:
    git:
    url: git://github.com/junqi/device_calendar.git
    ref: fix/ios17-request-permissions
  2. pub get
  3. add the following to your Info.plist
    <key>NSCalendarsFullAccessUsageDescription</key>
    <string>Access most functions for calendar viewing and editing.</string>
IVLIVS-III commented 1 year ago

I tested it, as long as I give the APP full permissions in the settings (full access to events), I can use it normally. This package just request write-only access to events now. Therefore, I think we should only need to update the package code, just request full access to events permissions

@Allenxuxu I just tested the example app (current state of develop branch, commit hash 3c24520) on iOS Simulator on iOS 17.0 and it "just works" fine. I get two prompts:

  1. request access (write-only) on app launch
  2. request full access, when trying to read events for the first time

What did you do differently?

A screen recording is attached below.

https://github.com/builttoroam/device_calendar/assets/48645716/c5aca14b-b77c-410f-8d1a-e7d63d04b515

YWD commented 11 months ago

Hello,When will this problem be solved?

kalismeras61 commented 11 months ago

device_calendar: git: url: git://github.com/junqi/device_calendar.git ref: fix/ios17-request-permissions

Use package as below

device_calendar:
    git:
      url: https://github.com/builttoroam/device_calendar.git
      ref: develop

and don't forget to add       info.plist

<key>NSCalendarsFullAccessUsageDescription</key>
<string>We need access to schedule calendar</string>
istornz commented 11 months ago

Do we have any estimated time when develop will be merged in stable?

Thanks 👍

manylittlestorms commented 11 months ago

Do we have any estimated time when develop will be merged in stable?

Thanks 👍

I have the same question 👍

Zahid046 commented 10 months ago

we need an update asap, as its affecting ios 17 user

Allenxuxu commented 10 months ago

Maybe this PR is useful: https://github.com/Baseflow/flutter-permission-handler/pull/1220

stephenjen commented 10 months ago

@kalismeras61 's method worked for me

JRSil commented 10 months ago

Do we have any estimated time when develop will be merged in stable?

Thanks 👍

Any update of it?

narritt commented 9 months ago
device_calendar:
    git:
      url: https://github.com/builttoroam/device_calendar.git
      ref: develop

<key>NSCalendarsFullAccessUsageDescription</key>
<string>We need access to schedule calendar</string>

Not the best way to fix it, because now the application requires full calendar access even if I need to add an event.

thomassth commented 9 months ago
device_calendar:
    git:
      url: https://github.com/builttoroam/device_calendar.git
      ref: develop

<key>NSCalendarsFullAccessUsageDescription</key>
<string>We need access to schedule calendar</string>

Not the best way to fix it, because now the application requires full calendar access even if I need to add an event.

What's the difference between the 2 APIs? Are they for different things, or it's like a tiered system?

devly13 commented 9 months ago

I have two errors using the GitHub Api: Swift Compiler Error (Xcode): Value of type 'EKEventStore' has no member 'requestFullAccessToEvents' Swift Compiler Error (Xcode): Type 'EKAuthorizationStatus' has no member 'fullAccess'

any ideas?

scolnet commented 8 months ago

Hello guys,

To complete this issue, and after fork master and merge with this pull request : https://github.com/builttoroam/device_calendar/pull/519 You can have another problem with real iphone devices to create calendar with the same exception PlatformException(500, That account does not allow calendars to be added or removed., null, null)

The problem is the getSource function (in SwiftDeviceCalendarPlugin.swift) which may don't retrieve the right account (for exemple, if you have several accounts gmail and neither iCloud account by default nor local account)

$0.sourceIdentifier == "iCloud" I don't know if it has been changed in iOS 17 but sourceIdentifier return an identifier like uuid the "iCloud" is in the title attribute. Also, I use the default Source in fallback solution.

So, when I test with `private func getSource() -> EKSource? {

  let localSources = eventStore.sources.filter { $0.sourceType == .local }

  if (!localSources.isEmpty) {
    return localSources.first
  }

  let iCloudSources = eventStore.sources.filter { $0.sourceType == .calDAV && $0.title == "iCloud" }

  if (!iCloudSources.isEmpty) {
    return iCloudSources.first
  }

  if let defaultSource = eventStore.defaultCalendarForNewEvents?.source {
    return defaultSource
  }

  return nil
}`

It's run perfectly on real device. Hope this helps

peng093 commented 5 months ago

I have two errors using the GitHub Api: Swift Compiler Error (Xcode): Value of type 'EKEventStore' has no member 'requestFullAccessToEvents' Swift Compiler Error (Xcode): Type 'EKAuthorizationStatus' has no member 'fullAccess'

any ideas? I have the same problem

stephenjen commented 3 months ago

I still encountered this issue yesterday where I got [(401, That account does not allow calendars to be added or removed., null, null)] after granting full access to calendars and then trying to retrieve calendars using:

await _deviceCalendarPlugin.retrieveCalendars()

I'm running iOS 17.2 on the stimulator.

Where I differ from the OP is instead of restarting my app, I noticed that if when I navigate to another screen that also uses this package and then navigate back to the screen where I encountered this issue, then my calendars would get retrieved without error.

After some trial and error, I realized that before await _deviceCalendarPlugin.retrieveCalendars() I need to first do a permission check by first running:

await _deviceCalendarPlugin.requestPermissions();

Before I would only run await _deviceCalendarPlugin.hasPermissions() before trying to retrieve calendars with await _deviceCalendarPlugin.retrieveCalendars().

Hope this helps.