capacitor-community / date-picker

Native DateTime Picker Plugin for Capacitor Apps
MIT License
87 stars 29 forks source link

Fatal error: Unexpectedly found nil while unwrapping an Optional value #83

Open smhemel opened 1 year ago

smhemel commented 1 year ago

Describe the bug Date Picker is not showing up. Getting Fatal error when I call atePicker.present() with valid options on Xcode.

My code:

DatePicker.present({
        mode: 'date',
        date: new Date().toISOString(),
        max: this.getMaxDate(from),
        theme: 'light',
      })
      .then((dateData) => {
         console.log(dateData);
      })

Error in Xcode: CapacitorCommunityDatePicker/Parse.swift:20: Fatal error: Unexpectedly found nil while unwrapping an Optional value

Screenshot 2023-09-10 at 12 34 37 AM
DanielDarrenJones commented 12 months ago

I'm getting this same issue, did you manage to find a solution @smhemel ? :)

smhemel commented 11 months ago

@DanielDarrenJones No, I didn't find any solution. But, I implemented a custom date-picker component using component instead of this plugin. Below, I have provided a screenshot. You can try it.

Screenshot 2024-05-14 234254

goodwin64 commented 6 months ago

We've faced the same error in our project recently. In our case we were passing the following data to the DatePicker:

let { value: newValue } = await DatePicker.present({
  mode, // "time"
  date: value || dateSuggestion || undefined, // 24-hour formatted time string
  timezone,
  format: dateFormat, // "HH:mm"
  is24h: true,
  ios: {
    timezone,
    format: dateFormat,
    style: 'wheels',
    mode,
  },
  android: {
    timezone,
    format: dateFormat,
    mode,
  },
});

Despite the fact we explicitly passed the is24h and format params the plugin used the device's platform built-in Date formatter (DateFormatter from the Foundation code) - so devices with the 12 hour locale tried to parse the 24-hour formatted time, which returned nil. The things became worse because there's a "must-have-a-value" operator used:

// client/node_modules/@capacitor-community/date-picker/ios/Plugin/Parse.swift
return formatter.date(from: date)!;
//                               ^--- here
Kamsou commented 4 months ago

Same error. @smhemel any idea ?

smhemel commented 4 months ago

Same error. @smhemel any idea ?

@Kamsou I didn't find any solution. Also, I did R&D to find an alternative date-picker plugin for the capacitor, but I didn't. After that, I implemented a custom date-picker component using component instead of this plugin. Below, I have provided a screenshot. You can try the component.

Screenshot 2024-05-14 234254