Skip to content

Commit

Permalink
removed uiLocalNotificationDateInterpretation parameter (#2461)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaikuB authored Nov 13, 2024
1 parent b6b9ae1 commit bc8fa20
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 109 deletions.
6 changes: 1 addition & 5 deletions flutter_local_notifications/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -705,15 +705,11 @@ await flutterLocalNotificationsPlugin.zonedSchedule(
android: AndroidNotificationDetails(
'your channel id', 'your channel name',
channelDescription: 'your channel description')),
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime);
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle);
```

On Android, the `androidScheduleMode` is used to determine the precision on when the notification would be delivered. In this example, it's been specified that it should appear at the exact time even when the device has entered a low-powered idle mode. Note that this requires that the exact alarm permission has been granted. If it's been revoked then the plugin will log an error message. Note that if the notification was scheduled to be recurring one but the permission had been revoked then it will no be scheduled as well. In either case, this is where developers may choose to schedule inexact notifications instead via the `androidScheduleMode` parameter.

The `uiLocalNotificationDateInterpretation` is required as on iOS versions older than 10 as time zone support is limited. This means it's not possible schedule a notification for another time zone and have iOS adjust the time the notification will appear when daylight saving time happens. With this parameter, it is used to determine if the scheduled date should be interpreted as absolute time or wall clock time.

There is an optional `matchDateTimeComponents` parameter that can be used to schedule a notification to appear on a daily or weekly basis by telling the plugin to match on the time or a combination of day of the week and time respectively.

If you are trying to update your code so it doesn't use the deprecated methods for showing daily or weekly notifications that occur on a specific day of the week then you'll need to perform calculations that would determine the next instance of a date that meets the conditions for your application. See the example application that shows one of the ways that can be done e.g. how schedule a weekly notification to occur on Monday 10:00AM.
Expand Down
12 changes: 3 additions & 9 deletions flutter_local_notifications/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1265,9 +1265,7 @@ class _HomePageState extends State<HomePage> {
priority: Priority.high,
importance: Importance.high,
fullScreenIntent: true)),
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime);
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle);

Navigator.pop(context);
},
Expand Down Expand Up @@ -1390,9 +1388,7 @@ class _HomePageState extends State<HomePage> {
android: AndroidNotificationDetails(
'your channel id', 'your channel name',
channelDescription: 'your channel description')),
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime);
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle);
}

Future<void> _zonedScheduleAlarmClockNotification() async {
Expand All @@ -1405,9 +1401,7 @@ class _HomePageState extends State<HomePage> {
android: AndroidNotificationDetails(
'alarm_clock_channel', 'Alarm Clock Channel',
channelDescription: 'Alarm Clock Notification')),
androidScheduleMode: AndroidScheduleMode.alarmClock,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime);
androidScheduleMode: AndroidScheduleMode.alarmClock);
}

Future<void> _showNotificationWithNoSound() async {
Expand Down
12 changes: 0 additions & 12 deletions flutter_local_notifications/example/lib/repeating.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ Future<void> _scheduleDailyTenAMLastYearNotification() async {
channelDescription: 'daily notification description'),
),
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.time);
}

Expand All @@ -97,8 +95,6 @@ Future<void> _scheduleWeeklyTenAMNotification() async {
channelDescription: 'weekly notificationdescription'),
),
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.dayOfWeekAndTime);
}

Expand All @@ -114,8 +110,6 @@ Future<void> _scheduleWeeklyMondayTenAMNotification() async {
channelDescription: 'weekly notificationdescription'),
),
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.dayOfWeekAndTime);
}

Expand All @@ -131,8 +125,6 @@ Future<void> _scheduleMonthlyMondayTenAMNotification() async {
channelDescription: 'monthly notificationdescription'),
),
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.dayOfMonthAndTime);
}

Expand All @@ -148,8 +140,6 @@ Future<void> _scheduleYearlyMondayTenAMNotification() async {
channelDescription: 'yearly notification description'),
),
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.dateAndTime);
}

Expand Down Expand Up @@ -199,8 +189,6 @@ Future<void> _scheduleDailyTenAMNotification() async {
channelDescription: 'daily notification description'),
),
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.time);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ @implementation FlutterLocalNotificationsPlugin {
NSString *const SCHEDULED_DATE_TIME = @"scheduledDateTimeISO8601";
NSString *const TIME_ZONE_NAME = @"timeZoneName";
NSString *const MATCH_DATE_TIME_COMPONENTS = @"matchDateTimeComponents";
NSString *const UILOCALNOTIFICATION_DATE_INTERPRETATION =
@"uiLocalNotificationDateInterpretation";

NSString *const NOTIFICATION_ID = @"NotificationId";
NSString *const PAYLOAD = @"payload";
Expand Down Expand Up @@ -121,11 +119,6 @@ typedef NS_ENUM(NSInteger, DateTimeComponents) {
DateAndTime
};

typedef NS_ENUM(NSInteger, UILocalNotificationDateInterpretation) {
AbsoluteGMTTime,
WallClockTime
};

static FlutterError *getFlutterError(NSError *error) {
return [FlutterError
errorWithCode:[NSString stringWithFormat:@"Error %d", (int)error.code]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export 'src/platform_specifics/darwin/notification_category.dart';
export 'src/platform_specifics/darwin/notification_category_option.dart';
export 'src/platform_specifics/darwin/notification_details.dart';
export 'src/platform_specifics/darwin/notification_enabled_options.dart';
export 'src/platform_specifics/ios/enums.dart';

export 'src/typedefs.dart';
export 'src/types.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'initialization_settings.dart';
import 'notification_details.dart';
import 'platform_flutter_local_notifications.dart';
import 'platform_specifics/android/schedule_mode.dart';
import 'platform_specifics/ios/enums.dart';
import 'types.dart';

/// Provides cross-platform functionality for displaying local notifications.
Expand Down Expand Up @@ -311,11 +310,6 @@ class FlutterLocalNotificationsPlugin {
/// platform channel in yyyy-mm-dd hh:mm:ss format. Therefore, the precision
/// is at the best to the second.
///
/// The [uiLocalNotificationDateInterpretation] is for iOS versions older
/// than 10 as the APIs have limited support for time zones. With this
/// parameter, it is used to determine if the scheduled date should be
/// interpreted as absolute time or wall clock time.
///
/// If a value for [matchDateTimeComponents] parameter is given, this tells
/// the plugin to schedule a recurring notification that matches the
/// specified date and time components. Specifying
Expand Down Expand Up @@ -343,8 +337,6 @@ class FlutterLocalNotificationsPlugin {
String? body,
TZDateTime scheduledDate,
NotificationDetails notificationDetails, {
required UILocalNotificationDateInterpretation
uiLocalNotificationDateInterpretation,
required AndroidScheduleMode androidScheduleMode,
String? payload,
DateTimeComponents? matchDateTimeComponents,
Expand All @@ -365,8 +357,6 @@ class FlutterLocalNotificationsPlugin {
IOSFlutterLocalNotificationsPlugin>()
?.zonedSchedule(
id, title, body, scheduledDate, notificationDetails.iOS,
uiLocalNotificationDateInterpretation:
uiLocalNotificationDateInterpretation,
payload: payload,
matchDateTimeComponents: matchDateTimeComponents);
} else if (defaultTargetPlatform == TargetPlatform.macOS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import 'platform_specifics/darwin/initialization_settings.dart';
import 'platform_specifics/darwin/mappers.dart';
import 'platform_specifics/darwin/notification_details.dart';
import 'platform_specifics/darwin/notification_enabled_options.dart';
import 'platform_specifics/ios/enums.dart';
import 'types.dart';
import 'tz_datetime_mapper.dart';

Expand Down Expand Up @@ -696,32 +695,17 @@ class IOSFlutterLocalNotificationsPlugin

/// Schedules a notification to be shown at the specified time in the
/// future in a specific time zone.
///
/// Due to the limited support for time zones provided the UILocalNotification
/// APIs used on devices using iOS versions older than 10, the
/// [uiLocalNotificationDateInterpretation] is needed to control how
/// [scheduledDate] is interpreted. See official docs at
/// https://developer.apple.com/documentation/uikit/uilocalnotification/1616659-timezone
/// for more details. Note that due to this limited support, it's likely that
/// on older iOS devices, there will still be issues with daylight saving time
/// except for when the time zone used in the [scheduledDate] matches the
/// device's time zone and [uiLocalNotificationDateInterpretation] is set to
/// [UILocalNotificationDateInterpretation.wallClockTime].
Future<void> zonedSchedule(
int id,
String? title,
String? body,
TZDateTime scheduledDate,
DarwinNotificationDetails? notificationDetails, {
required UILocalNotificationDateInterpretation
uiLocalNotificationDateInterpretation,
String? payload,
DateTimeComponents? matchDateTimeComponents,
}) async {
validateId(id);
validateDateIsInTheFuture(scheduledDate, matchDateTimeComponents);
ArgumentError.checkNotNull(uiLocalNotificationDateInterpretation,
'uiLocalNotificationDateInterpretation');
final Map<String, Object?> serializedPlatformSpecifics =
notificationDetails?.toMap() ?? <String, Object>{};
await _channel.invokeMethod(
Expand All @@ -732,8 +716,6 @@ class IOSFlutterLocalNotificationsPlugin
'body': body,
'platformSpecifics': serializedPlatformSpecifics,
'payload': payload ?? '',
'uiLocalNotificationDateInterpretation':
uiLocalNotificationDateInterpretation.index,
}
..addAll(scheduledDate.toMap())
..addAll(matchDateTimeComponents == null
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2186,9 +2186,7 @@ void main() {
'notification body',
scheduledDate,
const NotificationDetails(android: androidNotificationDetails),
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime);
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle);
expect(
log.last,
isMethodCall('zonedSchedule', arguments: <String, Object>{
Expand Down Expand Up @@ -2282,8 +2280,6 @@ void main() {
scheduledDate,
const NotificationDetails(android: androidNotificationDetails),
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.time);
expect(
log.last,
Expand Down Expand Up @@ -2379,8 +2375,6 @@ void main() {
scheduledDate,
const NotificationDetails(android: androidNotificationDetails),
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.dayOfWeekAndTime);
expect(
log.last,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,7 @@ void main() {
'notification body',
scheduledDate,
notificationDetails,
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime);
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle);

expect(
log.last,
Expand All @@ -522,8 +520,6 @@ void main() {
'title': 'notification title',
'body': 'notification body',
'payload': '',
'uiLocalNotificationDateInterpretation':
UILocalNotificationDateInterpretation.absoluteTime.index,
'scheduledDateTime': convertDateToISO8601String(scheduledDate),
'scheduledDateTimeISO8601': scheduledDate.toIso8601String(),
'timeZoneName': 'Australia/Sydney',
Expand Down Expand Up @@ -583,8 +579,6 @@ void main() {
scheduledDate,
notificationDetails,
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.time);

expect(
Expand All @@ -594,8 +588,6 @@ void main() {
'title': 'notification title',
'body': 'notification body',
'payload': '',
'uiLocalNotificationDateInterpretation':
UILocalNotificationDateInterpretation.absoluteTime.index,
'scheduledDateTime': convertDateToISO8601String(scheduledDate),
'scheduledDateTimeISO8601': scheduledDate.toIso8601String(),
'timeZoneName': 'Australia/Sydney',
Expand Down Expand Up @@ -656,8 +648,6 @@ void main() {
scheduledDate,
notificationDetails,
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.dayOfWeekAndTime);

expect(
Expand All @@ -667,8 +657,6 @@ void main() {
'title': 'notification title',
'body': 'notification body',
'payload': '',
'uiLocalNotificationDateInterpretation':
UILocalNotificationDateInterpretation.absoluteTime.index,
'scheduledDateTime': convertDateToISO8601String(scheduledDate),
'scheduledDateTimeISO8601': scheduledDate.toIso8601String(),
'timeZoneName': 'Australia/Sydney',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,15 +412,12 @@ void main() {
);

await flutterLocalNotificationsPlugin.zonedSchedule(
1,
'notification title',
'notification body',
scheduledDate,
notificationDetails,
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
);
1,
'notification title',
'notification body',
scheduledDate,
notificationDetails,
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle);

expect(
log.last,
Expand Down Expand Up @@ -490,8 +487,6 @@ void main() {
scheduledDate,
notificationDetails,
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.time,
);

Expand Down Expand Up @@ -568,8 +563,6 @@ void main() {
scheduledDate,
notificationDetails,
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.dayOfWeekAndTime,
);

Expand Down

0 comments on commit bc8fa20

Please sign in to comment.