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

eventId inconsistency between iOS and Android #509

Open borjandev opened 8 months ago

borjandev commented 8 months ago

Describe the bug Since the eventId is an essential parameter in determining which event is being modified, I would expect the eventId for the same exact event to be identical on both iOS and Android

To Reproduce Retrieve any event on iOS, then retrieve the same one on Android, compare their eventId

Expected behavior The eventId for the same exact event to be identical on both iOS and Android

Screenshots image

Device(s) tested Pixel 3 iPhone 12 mini Latest develop branch of device_calendar

Flutter doctor flutter 3.13.6 stable

Additional context If the current behavior is intended, is there any other id that can be used to uniquely identify the same event across iOS and Android?

IVLIVS-III commented 8 months ago

@borjandev this behavior could be classed as intended. More specifically, it is a limitation of the respective operating systems. Android and iOS generate the event id. device_calendar cannot influence their value.

You could attach notes / metadata to the event with an identifier generated by your code to uniquely identify the same event across operating systems. Keep in mind tho, users of your app could then always open their calendar application and modify or delete the notes / metadata themselves. Thus, this would not be fool-proof and could be tempered with by unsuspecting or malicious users of your app.

However, the event id does not change after creating the event. You could also store the auto-generated id for each operating system / device in your backend and correlate the different ids that way.

borjandev commented 8 months ago

Thank you for the info.

Some events are locked down and don't allow changes by participants, so the editing approach will fail in those cases as well, in addition to the overwriting concerns.

To make matters worse, the same event on 2 different iOS devices seem to report a different eventId, as well as the same calendar reports different calendarId..

Is this also considered intended behavior?

thomassth commented 8 months ago

Right now, device_calendar aims to expose as much native calendar outputs as possible. If iOS behaves like that, then we should expose the same values to devs.

If Apple's API can provide unique but consistent event IDs across devices, then sure we should do that. Otherwise I'd say it is unwise to scheme, create then maintain our own set of event IDs within this plugin. (Unless there's some sort of ISO standard? Then maybe it's worth the effort)

borjandev commented 8 months ago

@IVLIVS-III @thomassth After thorough investigation, both Apple and Google API's provide the remote id of the event and device_calendar is not currently handling it.

The corresponding Apple API reference :

https://developer.apple.com/documentation/eventkit/ekcalendaritem/1507283-calendaritemexternalidentifier

On iOS in SwiftDeviceCalendarPlugin.swift it can be retrieved like this :

let event = Event(
            externalEventId: ekEvent.calendarItemExternalIdentifier,
            eventId: ekEvent.eventIdentifier,
            calendarId: calendarId,
            ...

The corresponding Android API reference :

https://developer.android.com/reference/android/provider/CalendarContract.SyncColumns#_SYNC_ID

On Android in Constants.kt it can be retreived like this :

val EVENT_PROJECTION: Array<String> = arrayOf(
            CalendarContract.Events._SYNC_ID
            CalendarContract.Instances.EVENT_ID,
            CalendarContract.Events.TITLE,
            ...

Hope this helps so that device_calendar can expose it officially.