ebarooni / capacitor-calendar

The Capacitor Calendar Plugin enables full calendar functionality on iOS and Android, with added reminder support for iOS devices.
https://capacitor-calendar.pages.dev
MIT License
24 stars 7 forks source link

iOS createEventWithPrompt() throws error "Unable to retrieve view controller" #133

Closed dvag-steffen-hippeli closed 2 weeks ago

dvag-steffen-hippeli commented 3 weeks ago

"@capacitor/app": "6.0.0", "@capacitor/core": "6.1.1", "@capacitor/device": "6.0.0", "@capacitor/ios": "6.1.1",

Although the event was added successfully to the calendar the function gives me an error "Unable to retrieve view controller". (On Android no error occurs.)

This is how i use it:

try {
  const data = { title: event.summary,
    startDate: event.start.getTime(),
    endDate: event.end.getTime(),
    notes: event.description,
    location: event.location,
    url: event.url};
  if (this.platformService.isAndroidSmartphone()) {
    await CapacitorCalendar.requestPermission({alias: PluginPermission.READ_CALENDAR});
  }
  await CapacitorCalendar.createEventWithPrompt(data);
} catch (e) {}
ebarooni commented 3 weeks ago

@dvag-steffen-hippeli Which version of the plugin are you using? Also what phone do you use for testing and what iOS version does it have?

Edit: Since you said there was an error thrown but the event was created, did you get an event id back?

dvag-steffen-hippeli commented 3 weeks ago

Hi @ebarooni , thanks for your fast reply and excuse the missing information. I use version 6.7.0 of this package and tested on emulated iPhone 15 (all models) with iOS 17.5. Edit: As the function call throws the exception, there ist no id given back.

ebarooni commented 2 weeks ago

Hi @dvag-steffen-hippeli , I investigated a bit what you reported and i could not reproduce it. I tried the plugin v6.7.0 on real iPhone 14 Pro with iOS 17.5.1. I simply invoked the method with a title:

await CapacitorCalendar.createEventWithPrompt({ title: 'Test Event' });

The event got created and I received an event ID back.

Can you tell me what keys have you added to the Info.plist file? And how did you exactly call the method to result in what you reported (which option parameters did you use)? Maybe the issue is with a parameter other than title that i used for testing.

dvag-steffen-hippeli commented 2 weeks ago

Hello @ebarooni , i tested with only title as parameter

await CapacitorCalendar.createEventWithPrompt({title: 'event'});

but got the same error. In the plist file there are no entries concerning calendar or reminder as i only plan to use createEventWithPromt({}) to add events.

Here is the log from xcode:

⚡️ To Native -> CapacitorCalendar createEventWithPrompt 1708741 Error getting defaultTimedAlarmOffset: Error Domain=EKCADErrorDomain Code=1013 "Zugriff verweigert" UserInfo={NSLocalizedDescription=Zugriff verweigert} Error getting default calendar for new events: Error Domain=EKCADErrorDomain Code=1013 "Zugriff verweigert" UserInfo={NSLocalizedDescription=Zugriff verweigert} dealloc Query controller [59BCDE89-8C52-498B-956B-44913DD56E24] ERROR MESSAGE: {"errorMessage":"[CapacitorCalendar.createEventWithPrompt(:)] Unable to retrieve view controller","message":"[CapacitorCalendar.createEventWithPrompt(:)] Unable to retrieve view controller"} ⚡️ [error] - {"errorMessage":"[CapacitorCalendar.createEventWithPrompt(:)] Unable to retrieve view controller","message":"[CapacitorCalendar.createEventWithPrompt(:)] Unable to retrieve view controller"} VS terminated with error: Error Domain=_UIViewServiceErrorDomain Code=1 "(null)" UserInfo={Terminated=disconnect method} ⚡️ [log] - %c[App] background: #c71f19; color: #fff; track error {} GlobalErrorService ⚡️ To Native -> Crashes trackError 1708742 ⚡️ TO JS {"value":"64A41AD1-29B8-4BC5-A520-F7850A7C9854"}

Thanks

ebarooni commented 2 weeks ago

@dvag-steffen-hippeli I think i realized the confusion. In order for your app to perform read or write operations you need two steps:

  1. Include the corresponding key in your Info.plist file (either write only or full access – and have in mind different iOS version need different keys).
  2. Request the runtime permission for performing your operation.

In your case, your app needs write operation which means the corresponding key in your Info.plist is needed. However since you are only using createEventWithPrompt, you will not need to request runtime permission for write access.

In the scenario that you wanted to use createEvent, you should request the runtime permission as well.

dvag-steffen-hippeli commented 2 weeks ago

You are right, my mistake, thought no further permissions needed with createEventWithPrompt. I'll try that and let you know. Thank you

dvag-steffen-hippeli commented 2 weeks ago

I added the keys to the Info.plist (tried all) but still got the Error. If i check the runtime permission with CapacitorCalendar.requestPermission({alias: PluginPermission.WRITE_CALENDAR}); and grant permission, the Error does not occur on createEventWithPrompt. I go with this solution for now. Thanks for your help.

ebarooni commented 2 weeks ago

Alright. I will anyways double check that behavior. Because my expectation is (was) that only in keys in Info.plist should be enough. For now i will close this ticket.