Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zonedSchedule issue on IOS when time format is not 24H #860

Closed
psycura opened this issue Oct 18, 2020 · 10 comments · Fixed by #862
Closed

zonedSchedule issue on IOS when time format is not 24H #860

psycura opened this issue Oct 18, 2020 · 10 comments · Fixed by #862
Labels
help wanted Extra attention is needed

Comments

@psycura
Copy link
Contributor

psycura commented Oct 18, 2020

Hello, and thank you for this plugin.
But now i have some strange issue

Describe the bug
iPhone Xs Max
iOS 13.7
Flutter 1.22.2
plugin version 2.0.1+1

If iphone DateTime format is 24H = TRUE - Everything works as expected
But if i uninstall the app, change DateTime format is 24H = FALSE, and install app again, the App crushed when i try to send scheduled notification.

The console output from XCODE:

*** -[__NSCFCalendar components:fromDate:]: date cannot be nil
Future exception.
A few of these errors are going to be reported with this complaint, then further violations will simply be ignored.
Here is the backtrace where this occurred this time (some frames may be missing due to compiler optimizations):
(
0 CoreFoundation 0x00000001b2bbf3f8 C89C0E79-E3BA-397B-84AB-0B884D980499 + 95224
1 CoreFoundation 0x00000001b2bbe008 C89C0E79-E3BA-397B-84AB-0B884D980499 + 90120
2 flutter_local_notifications 0x0000000105eb2184 -[FlutterLocalNotificationsPlugin buildUserNotificationCalendarTrigger:] + 776
3 flutter_local_notifications 0x0000000105eaf5a0 -[FlutterLocalNotificationsPlugin zonedSchedule:result:] + 204
4 flutter_local_notifications 0x0000000105eaccfc -[FlutterLocalNotificationsPlugin handleMethodCall:result:] + 600
5 Flutter 0x0000000103ed16f4 __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 116
6 Flutter 0x0000000103690a54 _ZN7flutter15PlatformViewIOS21HandlePlatformMessageEN3fml6RefPtrINS_15PlatformMessageEEE + 504
7 Flutter 0x000000010396b2b8 _ZNSt3__110__function6__funcIZN7flutter5Shell29OnEngineHandlePlatformMessageEN3fml6RefPtrINS2_15PlatformMessageEEEE4$_33NS_9allocatorIS8_EEFvvEEclEv + 108
8 Flutter 0x0000000103699fe8 _ZN3fml15MessageLoopImpl10FlushTasksENS_9FlushTypeE + 1472
9 Flutter 0x000000010369c714 ZN3fml17MessageLoopDarwin11OnTimerFireEP16__CFRunLoopTimerPS0 + 32
10 CoreFoundation 0x00000001b2c553a8 C89C0E79-E3BA-397B-84AB-0B884D980499 + 709544
11 CoreFoundation 0x00000001b2c550c0 C89C0E79-E3BA-397B-84AB-0B884D980499 + 708800
12 CoreFoundation 0x00000001b2c54740 C89C0E79-E3BA-397B-84AB-0B884D980499 + 706368
13 CoreFoundation 0x00000001b2c4f538 C89C0E79-E3BA-397B-84AB-0B884D980499 + 685368
14 CoreFoundation 0x00000001b2c4ebc8 CFRunLoopRunSpecific + 480
15 GraphicsServices 0x00000001bd0375cc GSEventRunModal + 164
16 UIKitCore 0x00000001b6e01744 UIApplicationMain + 1936
17 Runner 0x0000000102e2499c main + 88
18 libdyld.dylib 0x00000001b2acb384 9D2487F7-16D3-31C3-B3DC-3566B9F6E707 + 4996
)
2020-10-18 13:42:40.686466+0300 Runner[6291:3308878] *** Assertion failure in -[UNCalendarNotificationTrigger _initWithDateComponents:repeats:], /Library/Caches/com.apple.xbs/Sources/UserNotifications/UserNotifications-281.6/UNNotificationTrigger.m:133
2020-10-18 13:42:40.688822+0300 Runner[6291:3308878] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'dateComponents must not be nil'
*** First throw call stack:
(0x1b2cd9344 0x1b29eecc0 0x1b2bd6878 0x1b3028160 0x1ba1a9ee8 0x1ba1a9d8c 0x105eb21b8 0x105eaf5a0 0x105eaccfc 0x103ed16f4 0x103690a54 0x10396b2b8 0x103699fe8 0x10369c714 0x1b2c553a8 0x1b2c550c0 0x1b2c54740 0x1b2c4f538 0x1b2c4ebc8 0x1bd0375cc 0x1b6e01744 0x102e2499c 0x1b2acb384)
libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'dateComponents must not be nil'
terminating with uncaught exception of type NSException
(lldb)

My method:

Future<void> scheduledNotification(
      LocalNotificationServiceModel notification) async {

    print('create zonedScheduleNotification dateTime:${notification.dateTime}');
    print(' local:${tz.local}');
    print(' absolute:${UILocalNotificationDateInterpretation.absoluteTime}');
    print('TZDateTime ${tz.TZDateTime.from(notification.dateTime, tz.local)}');

    return _flutterLocalNotificationsPlugin.zonedSchedule(
        notification.id,
        notification.title,
        notification.body,
        tz.TZDateTime.from(notification.dateTime, tz.local),
        _notificationDetails,
        payload: notification.payload,
        androidAllowWhileIdle: true,
        uiLocalNotificationDateInterpretation:
            UILocalNotificationDateInterpretation.absoluteTime);
  }

As result in console:

flutter: create zonedScheduleNotification dateTime:2020-10-21 12:00:00.000
flutter: local:Asia/Jerusalem
flutter: absolute:UILocalNotificationDateInterpretation.absoluteTime
flutter: TZDateTime 2020-10-21 12:00:00.000+0300

Also i've added print to your platform_flutter_local_notifications.dart to method zonedSchedule
print('FLN: zonedSchedule scheduledDate:$scheduledDate');

And also get this in console:

flutter: FLN: zonedSchedule scheduledDate:2020-10-21 12:00:00.000+0300

So as you can see i pass scheduledDate, but native code didn't receive it when IPHONE not in 24H format

To Reproduce

  1. Download example from your repo
  2. Change in pubspec.yaml - flutter_local_notifications: ^2.0.1+1
  3. Remove flutter: ">=1.12.13+hotfix.5"
  4. Run flutter pub get
  5. cd ios & pod install
  6. Toggle 24H format on iphone OFF
  7. Run in XCODE on real device
  8. Try to Schedule notification to appear in 5 seconds based on local time zone

Expected behavior
App should receive notification, but instead App is crashed with message from above

@MaikuB
Copy link
Owner

MaikuB commented Oct 18, 2020

My device has always had the 24hr time format setting off and don't run into the issue you've mentioned. I believe this is the default setting for iOS devices as well so there's probably something else going here. As I can't reproduce and you seem to be able to, it's likely you're the only one at this stage that can dig into this further. This will likely need some debugging on the iOS side to see what's going on

@psycura
Copy link
Contributor Author

psycura commented Oct 18, 2020

Strange, what i can do from my side to help you investigate it?

@MaikuB
Copy link
Owner

MaikuB commented Oct 18, 2020

Debug the code, find out where the issue lies and submit a PR to fix it as this isn't something I'm going to be able to do at all

@psycura
Copy link
Contributor Author

psycura commented Oct 18, 2020

The issue is happen on Native side, i`m not familiar with native ios development, so i cant really help in this manner

@MaikuB
Copy link
Owner

MaikuB commented Oct 18, 2020

Then I'm afraid it's simply something that just won't get fixed unless someone else is able to reproduce the issue to fix. The thing I've noticed though is you wrote what your method looks like yet the steps to reproduce revolve around the example app. Did you actually follow the steps you mentioned to reproduce the issue with the example app?

@psycura
Copy link
Contributor Author

psycura commented Oct 18, 2020

yes, i have this issue on my app, but for open bug i especially downloaded your example and did a try on your code, with only changes that i described

@MaikuB
Copy link
Owner

MaikuB commented Oct 18, 2020

I'll put a label on this issue to see if anyone else is able to help

@MaikuB MaikuB added the help wanted Extra attention is needed label Oct 18, 2020
@psycura
Copy link
Contributor Author

psycura commented Oct 18, 2020

Thanks

@MaikuB
Copy link
Owner

MaikuB commented Oct 18, 2020

I would still say your best bet is to upskill in native development enough to look at solving the issue yourself as it's quite possible that no one helps to look into this issue :S

psycura pushed a commit to psycura/flutter_local_notifications that referenced this issue Oct 19, 2020
@psycura
Copy link
Contributor Author

psycura commented Oct 19, 2020

I found a solution and did a PR #862
Please check

MaikuB added a commit that referenced this issue Oct 20, 2020
…iOS and macOS (#862)

* Fix for issue #860

* change locale for en_US_POSIX

* change locale for en_US_POSIX

* specify locale to ensure DateFormatter works on fixed format string for macOS

* bump plugin version to 2.0.2 and add changelog entry

* correct changelog entry

Co-authored-by: Eugene Alitz <alitze2@medtronic.com>
Co-authored-by: Michael Bui <25263378+MaikuB@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants