Skip to content

Commit c72971d

Browse files
authored
removed deprecated methods that scheduled notifications without a timezone (#2014)
1 parent 553d5fb commit c72971d

File tree

7 files changed

+9
-454
lines changed

7 files changed

+9
-454
lines changed

flutter_local_notifications/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# [vNext]
2+
3+
* **Breaking change** removed deprecated `schedule`, `showDailyAtTime` and `showWeeklyAtDayAndTime` methods. Notifications that were scheduled prior to this release should still work
4+
* **Breaking change** removed `Time` class
5+
16
# [14.1.1]
27

38
* Fixed typo in API docs for the deprecated `showDailyAtTime()` method. Thanks to the PR from [Yuichiro Kawano](https://github.com/yu1ro)

flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,8 @@ public class FlutterLocalNotificationsPlugin
147147
private static final String SHOW_METHOD = "show";
148148
private static final String CANCEL_METHOD = "cancel";
149149
private static final String CANCEL_ALL_METHOD = "cancelAll";
150-
private static final String SCHEDULE_METHOD = "schedule";
151150
private static final String ZONED_SCHEDULE_METHOD = "zonedSchedule";
152151
private static final String PERIODICALLY_SHOW_METHOD = "periodicallyShow";
153-
private static final String SHOW_DAILY_AT_TIME_METHOD = "showDailyAtTime";
154-
private static final String SHOW_WEEKLY_AT_DAY_AND_TIME_METHOD = "showWeeklyAtDayAndTime";
155152
private static final String GET_NOTIFICATION_APP_LAUNCH_DETAILS_METHOD =
156153
"getNotificationAppLaunchDetails";
157154
private static final String REQUEST_PERMISSION_METHOD = "requestPermission";
@@ -524,6 +521,8 @@ private static Spanned fromHtml(String html) {
524521
}
525522
}
526523

524+
// This is left to support old apps need this done when a notification is rescheduled and used the
525+
// deprecated schedule() method of the plugin
527526
private static void scheduleNotification(
528527
Context context,
529528
final NotificationDetails notificationDetails,
@@ -1371,9 +1370,6 @@ public void onMethodCall(MethodCall call, @NonNull Result result) {
13711370
case SHOW_METHOD:
13721371
show(call, result);
13731372
break;
1374-
case SCHEDULE_METHOD:
1375-
schedule(call, result);
1376-
break;
13771373
case ZONED_SCHEDULE_METHOD:
13781374
zonedSchedule(call, result);
13791375
break;
@@ -1392,8 +1388,6 @@ public void fail(String message) {
13921388
});
13931389
break;
13941390
case PERIODICALLY_SHOW_METHOD:
1395-
case SHOW_DAILY_AT_TIME_METHOD:
1396-
case SHOW_WEEKLY_AT_DAY_AND_TIME_METHOD:
13971391
repeat(call, result);
13981392
break;
13991393
case CANCEL_METHOD:
@@ -1512,18 +1506,6 @@ private void repeat(MethodCall call, Result result) {
15121506
}
15131507
}
15141508

1515-
private void schedule(MethodCall call, Result result) {
1516-
NotificationDetails notificationDetails = extractNotificationDetails(result, call.arguments());
1517-
if (notificationDetails != null) {
1518-
try {
1519-
scheduleNotification(applicationContext, notificationDetails, true);
1520-
result.success(null);
1521-
} catch (PluginException e) {
1522-
result.error(e.code, e.getMessage(), null);
1523-
}
1524-
}
1525-
}
1526-
15271509
private void zonedSchedule(MethodCall call, Result result) {
15281510
NotificationDetails notificationDetails = extractNotificationDetails(result, call.arguments());
15291511
if (notificationDetails != null) {

flutter_local_notifications/ios/Classes/FlutterLocalNotificationsPlugin.m

Lines changed: 0 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@ @implementation FlutterLocalNotificationsPlugin {
2323
NSString *const INITIALIZE_METHOD = @"initialize";
2424
NSString *const GET_CALLBACK_METHOD = @"getCallbackHandle";
2525
NSString *const SHOW_METHOD = @"show";
26-
NSString *const SCHEDULE_METHOD = @"schedule";
2726
NSString *const ZONED_SCHEDULE_METHOD = @"zonedSchedule";
2827
NSString *const PERIODICALLY_SHOW_METHOD = @"periodicallyShow";
29-
NSString *const SHOW_DAILY_AT_TIME_METHOD = @"showDailyAtTime";
30-
NSString *const SHOW_WEEKLY_AT_DAY_AND_TIME_METHOD = @"showWeeklyAtDayAndTime";
3128
NSString *const CANCEL_METHOD = @"cancel";
3229
NSString *const CANCEL_ALL_METHOD = @"cancelAll";
3330
NSString *const PENDING_NOTIFICATIONS_REQUESTS_METHOD =
@@ -77,10 +74,6 @@ @implementation FlutterLocalNotificationsPlugin {
7774
NSString *const BADGE_NUMBER = @"badgeNumber";
7875
NSString *const MILLISECONDS_SINCE_EPOCH = @"millisecondsSinceEpoch";
7976
NSString *const REPEAT_INTERVAL = @"repeatInterval";
80-
NSString *const REPEAT_TIME = @"repeatTime";
81-
NSString *const HOUR = @"hour";
82-
NSString *const MINUTE = @"minute";
83-
NSString *const SECOND = @"second";
8477
NSString *const SCHEDULED_DATE_TIME = @"scheduledDateTimeISO8601";
8578
NSString *const TIME_ZONE_NAME = @"timeZoneName";
8679
NSString *const MATCH_DATE_TIME_COMPONENTS = @"matchDateTimeComponents";
@@ -167,14 +160,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call
167160
[self show:call.arguments result:result];
168161
} else if ([ZONED_SCHEDULE_METHOD isEqualToString:call.method]) {
169162
[self zonedSchedule:call.arguments result:result];
170-
} else if ([SCHEDULE_METHOD isEqualToString:call.method]) {
171-
[self schedule:call.arguments result:result];
172163
} else if ([PERIODICALLY_SHOW_METHOD isEqualToString:call.method]) {
173164
[self periodicallyShow:call.arguments result:result];
174-
} else if ([SHOW_DAILY_AT_TIME_METHOD isEqualToString:call.method]) {
175-
[self showDailyAtTime:call.arguments result:result];
176-
} else if ([SHOW_WEEKLY_AT_DAY_AND_TIME_METHOD isEqualToString:call.method]) {
177-
[self showWeeklyAtDayAndTime:call.arguments result:result];
178165
} else if ([REQUEST_PERMISSIONS_METHOD isEqualToString:call.method]) {
179166
[self requestPermissions:call.arguments result:result];
180167
} else if ([CANCEL_METHOD isEqualToString:call.method]) {
@@ -660,44 +647,6 @@ - (void)zonedSchedule:(NSDictionary *_Nonnull)arguments
660647
}
661648
}
662649

663-
- (void)schedule:(NSDictionary *_Nonnull)arguments
664-
result:(FlutterResult _Nonnull)result {
665-
NSNumber *secondsSinceEpoch =
666-
@([arguments[MILLISECONDS_SINCE_EPOCH] longLongValue] / 1000);
667-
if (@available(iOS 10.0, *)) {
668-
UNMutableNotificationContent *content =
669-
[self buildStandardNotificationContent:arguments result:result];
670-
NSDate *date = [NSDate
671-
dateWithTimeIntervalSince1970:[secondsSinceEpoch longLongValue]];
672-
NSCalendar *calendar = [NSCalendar currentCalendar];
673-
NSDateComponents *dateComponents =
674-
[calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth |
675-
NSCalendarUnitDay | NSCalendarUnitHour |
676-
NSCalendarUnitMinute | NSCalendarUnitSecond)
677-
fromDate:date];
678-
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger
679-
triggerWithDateMatchingComponents:dateComponents
680-
repeats:false];
681-
[self addNotificationRequest:[self getIdentifier:arguments]
682-
content:content
683-
result:result
684-
trigger:trigger];
685-
} else {
686-
#pragma clang diagnostic push
687-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
688-
UILocalNotification *notification =
689-
[self buildStandardUILocalNotification:arguments];
690-
#pragma clang diagnostic pop
691-
notification.fireDate = [NSDate
692-
dateWithTimeIntervalSince1970:[secondsSinceEpoch longLongValue]];
693-
#pragma clang diagnostic push
694-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
695-
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
696-
#pragma clang diagnostic pop
697-
result(nil);
698-
}
699-
}
700-
701650
- (void)periodicallyShow:(NSDictionary *_Nonnull)arguments
702651
result:(FlutterResult _Nonnull)result {
703652
if (@available(iOS 10.0, *)) {
@@ -743,91 +692,6 @@ - (void)periodicallyShow:(NSDictionary *_Nonnull)arguments
743692
}
744693
}
745694

746-
- (void)showDailyAtTime:(NSDictionary *_Nonnull)arguments
747-
result:(FlutterResult _Nonnull)result {
748-
NSDictionary *timeArguments = (NSDictionary *)arguments[REPEAT_TIME];
749-
NSNumber *hourComponent = timeArguments[HOUR];
750-
NSNumber *minutesComponent = timeArguments[MINUTE];
751-
NSNumber *secondsComponent = timeArguments[SECOND];
752-
if (@available(iOS 10.0, *)) {
753-
UNMutableNotificationContent *content =
754-
[self buildStandardNotificationContent:arguments result:result];
755-
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
756-
[dateComponents setHour:[hourComponent integerValue]];
757-
[dateComponents setMinute:[minutesComponent integerValue]];
758-
[dateComponents setSecond:[secondsComponent integerValue]];
759-
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger
760-
triggerWithDateMatchingComponents:dateComponents
761-
repeats:YES];
762-
[self addNotificationRequest:[self getIdentifier:arguments]
763-
content:content
764-
result:result
765-
trigger:trigger];
766-
} else {
767-
#pragma clang diagnostic push
768-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
769-
UILocalNotification *notification =
770-
[self buildStandardUILocalNotification:arguments];
771-
#pragma clang diagnostic pop
772-
notification.repeatInterval = NSCalendarUnitDay;
773-
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
774-
[dateComponents setHour:[hourComponent integerValue]];
775-
[dateComponents setMinute:[minutesComponent integerValue]];
776-
[dateComponents setSecond:[secondsComponent integerValue]];
777-
NSCalendar *calendar = [NSCalendar currentCalendar];
778-
notification.fireDate = [calendar dateFromComponents:dateComponents];
779-
#pragma clang diagnostic push
780-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
781-
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
782-
#pragma clang diagnostic pop
783-
result(nil);
784-
}
785-
}
786-
787-
- (void)showWeeklyAtDayAndTime:(NSDictionary *_Nonnull)arguments
788-
result:(FlutterResult _Nonnull)result {
789-
NSDictionary *timeArguments = (NSDictionary *)arguments[REPEAT_TIME];
790-
NSNumber *dayOfWeekComponent = arguments[DAY];
791-
NSNumber *hourComponent = timeArguments[HOUR];
792-
NSNumber *minutesComponent = timeArguments[MINUTE];
793-
NSNumber *secondsComponent = timeArguments[SECOND];
794-
if (@available(iOS 10.0, *)) {
795-
UNMutableNotificationContent *content =
796-
[self buildStandardNotificationContent:arguments result:result];
797-
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
798-
[dateComponents setHour:[hourComponent integerValue]];
799-
[dateComponents setMinute:[minutesComponent integerValue]];
800-
[dateComponents setSecond:[secondsComponent integerValue]];
801-
[dateComponents setWeekday:[dayOfWeekComponent integerValue]];
802-
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger
803-
triggerWithDateMatchingComponents:dateComponents
804-
repeats:YES];
805-
[self addNotificationRequest:[self getIdentifier:arguments]
806-
content:content
807-
result:result
808-
trigger:trigger];
809-
} else {
810-
#pragma clang diagnostic push
811-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
812-
UILocalNotification *notification =
813-
[self buildStandardUILocalNotification:arguments];
814-
#pragma clang diagnostic pop
815-
notification.repeatInterval = NSCalendarUnitWeekOfYear;
816-
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
817-
[dateComponents setHour:[hourComponent integerValue]];
818-
[dateComponents setMinute:[minutesComponent integerValue]];
819-
[dateComponents setSecond:[secondsComponent integerValue]];
820-
[dateComponents setWeekday:[dayOfWeekComponent integerValue]];
821-
NSCalendar *calendar = [NSCalendar currentCalendar];
822-
notification.fireDate = [calendar dateFromComponents:dateComponents];
823-
#pragma clang diagnostic push
824-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
825-
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
826-
#pragma clang diagnostic pop
827-
result(nil);
828-
}
829-
}
830-
831695
- (void)cancel:(NSNumber *)id result:(FlutterResult _Nonnull)result {
832696
if (@available(iOS 10.0, *)) {
833697
UNUserNotificationCenter *center =

flutter_local_notifications/lib/src/flutter_local_notifications_plugin.dart

Lines changed: 2 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -293,44 +293,6 @@ class FlutterLocalNotificationsPlugin {
293293
await FlutterLocalNotificationsPlatform.instance.cancelAll();
294294
}
295295

296-
/// Schedules a notification to be shown at the specified date and time.
297-
///
298-
/// The [androidAllowWhileIdle] parameter determines if the notification
299-
/// should still be shown at the exact time even when the device is in a
300-
/// low-power idle mode.
301-
@Deprecated('Deprecated due to problems with time zones. Use zonedSchedule '
302-
'instead.')
303-
Future<void> schedule(
304-
int id,
305-
String? title,
306-
String? body,
307-
DateTime scheduledDate,
308-
NotificationDetails notificationDetails, {
309-
String? payload,
310-
@Deprecated('Deprecated in favor of the androidScheduleMode parameter')
311-
bool androidAllowWhileIdle = false,
312-
AndroidScheduleMode? androidScheduleMode,
313-
}) async {
314-
if (kIsWeb) {
315-
return;
316-
}
317-
if (defaultTargetPlatform == TargetPlatform.android) {
318-
await resolvePlatformSpecificImplementation<
319-
AndroidFlutterLocalNotificationsPlugin>()!
320-
.schedule(id, title, body, scheduledDate, notificationDetails.android,
321-
payload: payload,
322-
scheduleMode: _chooseScheduleMode(
323-
androidScheduleMode, androidAllowWhileIdle));
324-
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
325-
await resolvePlatformSpecificImplementation<
326-
IOSFlutterLocalNotificationsPlugin>()
327-
?.schedule(id, title, body, scheduledDate, notificationDetails.iOS,
328-
payload: payload);
329-
} else if (defaultTargetPlatform == TargetPlatform.macOS) {
330-
throw UnimplementedError();
331-
}
332-
}
333-
334296
/// Schedules a notification to be shown at the specified date and time
335297
/// relative to a specific time zone.
336298
///
@@ -374,7 +336,7 @@ class FlutterLocalNotificationsPlugin {
374336
required UILocalNotificationDateInterpretation
375337
uiLocalNotificationDateInterpretation,
376338
@Deprecated('Deprecated in favor of the androidScheduleMode parameter')
377-
bool androidAllowWhileIdle = false,
339+
bool androidAllowWhileIdle = false,
378340
AndroidScheduleMode? androidScheduleMode,
379341
String? payload,
380342
DateTimeComponents? matchDateTimeComponents,
@@ -439,7 +401,7 @@ class FlutterLocalNotificationsPlugin {
439401
NotificationDetails notificationDetails, {
440402
String? payload,
441403
@Deprecated('Deprecated in favor of the androidScheduleMode parameter')
442-
bool androidAllowWhileIdle = false,
404+
bool androidAllowWhileIdle = false,
443405
AndroidScheduleMode? androidScheduleMode,
444406
}) async {
445407
if (kIsWeb) {
@@ -476,75 +438,6 @@ class FlutterLocalNotificationsPlugin {
476438
? AndroidScheduleMode.exactAllowWhileIdle
477439
: AndroidScheduleMode.exact);
478440

479-
/// Shows a notification on a daily interval at the specified time.
480-
@Deprecated(
481-
'Deprecated due to problems with time zones. Use zonedSchedule instead '
482-
'by passing a date in the future with the same time and pass '
483-
'DateTimeComponents.time as the value of the '
484-
'matchDateTimeComponents parameter.')
485-
Future<void> showDailyAtTime(
486-
int id,
487-
String? title,
488-
String? body,
489-
Time notificationTime,
490-
NotificationDetails notificationDetails, {
491-
String? payload,
492-
}) async {
493-
if (kIsWeb) {
494-
return;
495-
}
496-
if (defaultTargetPlatform == TargetPlatform.android) {
497-
await resolvePlatformSpecificImplementation<
498-
AndroidFlutterLocalNotificationsPlugin>()
499-
?.showDailyAtTime(
500-
id, title, body, notificationTime, notificationDetails.android,
501-
payload: payload);
502-
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
503-
await resolvePlatformSpecificImplementation<
504-
IOSFlutterLocalNotificationsPlugin>()
505-
?.showDailyAtTime(
506-
id, title, body, notificationTime, notificationDetails.iOS,
507-
payload: payload);
508-
} else if (defaultTargetPlatform == TargetPlatform.macOS) {
509-
throw UnimplementedError();
510-
}
511-
}
512-
513-
/// Shows a notification on weekly interval at the specified day and time.
514-
@Deprecated(
515-
'Deprecated due to problems with time zones. Use zonedSchedule instead '
516-
'by passing a date in the future with the same day of the week and time '
517-
'as well as passing DateTimeComponents.dayOfWeekAndTime as the value of '
518-
'the matchDateTimeComponents parameter.')
519-
Future<void> showWeeklyAtDayAndTime(
520-
int id,
521-
String? title,
522-
String? body,
523-
Day day,
524-
Time notificationTime,
525-
NotificationDetails notificationDetails, {
526-
String? payload,
527-
}) async {
528-
if (kIsWeb) {
529-
return;
530-
}
531-
if (defaultTargetPlatform == TargetPlatform.android) {
532-
await resolvePlatformSpecificImplementation<
533-
AndroidFlutterLocalNotificationsPlugin>()
534-
?.showWeeklyAtDayAndTime(id, title, body, day, notificationTime,
535-
notificationDetails.android,
536-
payload: payload);
537-
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
538-
await resolvePlatformSpecificImplementation<
539-
IOSFlutterLocalNotificationsPlugin>()
540-
?.showWeeklyAtDayAndTime(
541-
id, title, body, day, notificationTime, notificationDetails.iOS,
542-
payload: payload);
543-
} else if (defaultTargetPlatform == TargetPlatform.macOS) {
544-
throw UnimplementedError();
545-
}
546-
}
547-
548441
/// Returns a list of notifications pending to be delivered/shown.
549442
Future<List<PendingNotificationRequest>> pendingNotificationRequests() =>
550443
FlutterLocalNotificationsPlatform.instance.pendingNotificationRequests();

0 commit comments

Comments
 (0)