Skip to content

Commit

Permalink
removed deprecated methods that scheduled notifications without a tim…
Browse files Browse the repository at this point in the history
…ezone
  • Loading branch information
MaikuB committed Jun 1, 2023
1 parent 553d5fb commit 6f5c3e8
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 454 deletions.
5 changes: 5 additions & 0 deletions flutter_local_notifications/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# [vNext]

* **Breaking change** removed deprecated `schedule`, `showDailyAtTime` and `showWeeklyAtDayAndTime` methods. Notifications that were scheduled prior to this release should still work
* **Breaking change** removed `Time` class

# [14.1.1]

* Fixed typo in API docs for the deprecated `showDailyAtTime()` method. Thanks to the PR from [Yuichiro Kawano](https://github.com/yu1ro)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,8 @@ public class FlutterLocalNotificationsPlugin
private static final String SHOW_METHOD = "show";
private static final String CANCEL_METHOD = "cancel";
private static final String CANCEL_ALL_METHOD = "cancelAll";
private static final String SCHEDULE_METHOD = "schedule";
private static final String ZONED_SCHEDULE_METHOD = "zonedSchedule";
private static final String PERIODICALLY_SHOW_METHOD = "periodicallyShow";
private static final String SHOW_DAILY_AT_TIME_METHOD = "showDailyAtTime";
private static final String SHOW_WEEKLY_AT_DAY_AND_TIME_METHOD = "showWeeklyAtDayAndTime";
private static final String GET_NOTIFICATION_APP_LAUNCH_DETAILS_METHOD =
"getNotificationAppLaunchDetails";
private static final String REQUEST_PERMISSION_METHOD = "requestPermission";
Expand Down Expand Up @@ -524,6 +521,8 @@ private static Spanned fromHtml(String html) {
}
}

// This is left to support old apps need this done when a notification is rescheduled and used the
// deprecated schedule() method of the plugin
private static void scheduleNotification(
Context context,
final NotificationDetails notificationDetails,
Expand Down Expand Up @@ -1371,9 +1370,6 @@ public void onMethodCall(MethodCall call, @NonNull Result result) {
case SHOW_METHOD:
show(call, result);
break;
case SCHEDULE_METHOD:
schedule(call, result);
break;
case ZONED_SCHEDULE_METHOD:
zonedSchedule(call, result);
break;
Expand All @@ -1392,8 +1388,6 @@ public void fail(String message) {
});
break;
case PERIODICALLY_SHOW_METHOD:
case SHOW_DAILY_AT_TIME_METHOD:
case SHOW_WEEKLY_AT_DAY_AND_TIME_METHOD:
repeat(call, result);
break;
case CANCEL_METHOD:
Expand Down Expand Up @@ -1512,18 +1506,6 @@ private void repeat(MethodCall call, Result result) {
}
}

private void schedule(MethodCall call, Result result) {
NotificationDetails notificationDetails = extractNotificationDetails(result, call.arguments());
if (notificationDetails != null) {
try {
scheduleNotification(applicationContext, notificationDetails, true);
result.success(null);
} catch (PluginException e) {
result.error(e.code, e.getMessage(), null);
}
}
}

private void zonedSchedule(MethodCall call, Result result) {
NotificationDetails notificationDetails = extractNotificationDetails(result, call.arguments());
if (notificationDetails != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ @implementation FlutterLocalNotificationsPlugin {
NSString *const INITIALIZE_METHOD = @"initialize";
NSString *const GET_CALLBACK_METHOD = @"getCallbackHandle";
NSString *const SHOW_METHOD = @"show";
NSString *const SCHEDULE_METHOD = @"schedule";
NSString *const ZONED_SCHEDULE_METHOD = @"zonedSchedule";
NSString *const PERIODICALLY_SHOW_METHOD = @"periodicallyShow";
NSString *const SHOW_DAILY_AT_TIME_METHOD = @"showDailyAtTime";
NSString *const SHOW_WEEKLY_AT_DAY_AND_TIME_METHOD = @"showWeeklyAtDayAndTime";
NSString *const CANCEL_METHOD = @"cancel";
NSString *const CANCEL_ALL_METHOD = @"cancelAll";
NSString *const PENDING_NOTIFICATIONS_REQUESTS_METHOD =
Expand Down Expand Up @@ -77,10 +74,6 @@ @implementation FlutterLocalNotificationsPlugin {
NSString *const BADGE_NUMBER = @"badgeNumber";
NSString *const MILLISECONDS_SINCE_EPOCH = @"millisecondsSinceEpoch";
NSString *const REPEAT_INTERVAL = @"repeatInterval";
NSString *const REPEAT_TIME = @"repeatTime";
NSString *const HOUR = @"hour";
NSString *const MINUTE = @"minute";
NSString *const SECOND = @"second";
NSString *const SCHEDULED_DATE_TIME = @"scheduledDateTimeISO8601";
NSString *const TIME_ZONE_NAME = @"timeZoneName";
NSString *const MATCH_DATE_TIME_COMPONENTS = @"matchDateTimeComponents";
Expand Down Expand Up @@ -167,14 +160,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call
[self show:call.arguments result:result];
} else if ([ZONED_SCHEDULE_METHOD isEqualToString:call.method]) {
[self zonedSchedule:call.arguments result:result];
} else if ([SCHEDULE_METHOD isEqualToString:call.method]) {
[self schedule:call.arguments result:result];
} else if ([PERIODICALLY_SHOW_METHOD isEqualToString:call.method]) {
[self periodicallyShow:call.arguments result:result];
} else if ([SHOW_DAILY_AT_TIME_METHOD isEqualToString:call.method]) {
[self showDailyAtTime:call.arguments result:result];
} else if ([SHOW_WEEKLY_AT_DAY_AND_TIME_METHOD isEqualToString:call.method]) {
[self showWeeklyAtDayAndTime:call.arguments result:result];
} else if ([REQUEST_PERMISSIONS_METHOD isEqualToString:call.method]) {
[self requestPermissions:call.arguments result:result];
} else if ([CANCEL_METHOD isEqualToString:call.method]) {
Expand Down Expand Up @@ -660,44 +647,6 @@ - (void)zonedSchedule:(NSDictionary *_Nonnull)arguments
}
}

- (void)schedule:(NSDictionary *_Nonnull)arguments
result:(FlutterResult _Nonnull)result {
NSNumber *secondsSinceEpoch =
@([arguments[MILLISECONDS_SINCE_EPOCH] longLongValue] / 1000);
if (@available(iOS 10.0, *)) {
UNMutableNotificationContent *content =
[self buildStandardNotificationContent:arguments result:result];
NSDate *date = [NSDate
dateWithTimeIntervalSince1970:[secondsSinceEpoch longLongValue]];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *dateComponents =
[calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth |
NSCalendarUnitDay | NSCalendarUnitHour |
NSCalendarUnitMinute | NSCalendarUnitSecond)
fromDate:date];
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger
triggerWithDateMatchingComponents:dateComponents
repeats:false];
[self addNotificationRequest:[self getIdentifier:arguments]
content:content
result:result
trigger:trigger];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
UILocalNotification *notification =
[self buildStandardUILocalNotification:arguments];
#pragma clang diagnostic pop
notification.fireDate = [NSDate
dateWithTimeIntervalSince1970:[secondsSinceEpoch longLongValue]];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
#pragma clang diagnostic pop
result(nil);
}
}

- (void)periodicallyShow:(NSDictionary *_Nonnull)arguments
result:(FlutterResult _Nonnull)result {
if (@available(iOS 10.0, *)) {
Expand Down Expand Up @@ -743,91 +692,6 @@ - (void)periodicallyShow:(NSDictionary *_Nonnull)arguments
}
}

- (void)showDailyAtTime:(NSDictionary *_Nonnull)arguments
result:(FlutterResult _Nonnull)result {
NSDictionary *timeArguments = (NSDictionary *)arguments[REPEAT_TIME];
NSNumber *hourComponent = timeArguments[HOUR];
NSNumber *minutesComponent = timeArguments[MINUTE];
NSNumber *secondsComponent = timeArguments[SECOND];
if (@available(iOS 10.0, *)) {
UNMutableNotificationContent *content =
[self buildStandardNotificationContent:arguments result:result];
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
[dateComponents setHour:[hourComponent integerValue]];
[dateComponents setMinute:[minutesComponent integerValue]];
[dateComponents setSecond:[secondsComponent integerValue]];
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger
triggerWithDateMatchingComponents:dateComponents
repeats:YES];
[self addNotificationRequest:[self getIdentifier:arguments]
content:content
result:result
trigger:trigger];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
UILocalNotification *notification =
[self buildStandardUILocalNotification:arguments];
#pragma clang diagnostic pop
notification.repeatInterval = NSCalendarUnitDay;
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
[dateComponents setHour:[hourComponent integerValue]];
[dateComponents setMinute:[minutesComponent integerValue]];
[dateComponents setSecond:[secondsComponent integerValue]];
NSCalendar *calendar = [NSCalendar currentCalendar];
notification.fireDate = [calendar dateFromComponents:dateComponents];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
#pragma clang diagnostic pop
result(nil);
}
}

- (void)showWeeklyAtDayAndTime:(NSDictionary *_Nonnull)arguments
result:(FlutterResult _Nonnull)result {
NSDictionary *timeArguments = (NSDictionary *)arguments[REPEAT_TIME];
NSNumber *dayOfWeekComponent = arguments[DAY];
NSNumber *hourComponent = timeArguments[HOUR];
NSNumber *minutesComponent = timeArguments[MINUTE];
NSNumber *secondsComponent = timeArguments[SECOND];
if (@available(iOS 10.0, *)) {
UNMutableNotificationContent *content =
[self buildStandardNotificationContent:arguments result:result];
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
[dateComponents setHour:[hourComponent integerValue]];
[dateComponents setMinute:[minutesComponent integerValue]];
[dateComponents setSecond:[secondsComponent integerValue]];
[dateComponents setWeekday:[dayOfWeekComponent integerValue]];
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger
triggerWithDateMatchingComponents:dateComponents
repeats:YES];
[self addNotificationRequest:[self getIdentifier:arguments]
content:content
result:result
trigger:trigger];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
UILocalNotification *notification =
[self buildStandardUILocalNotification:arguments];
#pragma clang diagnostic pop
notification.repeatInterval = NSCalendarUnitWeekOfYear;
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
[dateComponents setHour:[hourComponent integerValue]];
[dateComponents setMinute:[minutesComponent integerValue]];
[dateComponents setSecond:[secondsComponent integerValue]];
[dateComponents setWeekday:[dayOfWeekComponent integerValue]];
NSCalendar *calendar = [NSCalendar currentCalendar];
notification.fireDate = [calendar dateFromComponents:dateComponents];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
#pragma clang diagnostic pop
result(nil);
}
}

- (void)cancel:(NSNumber *)id result:(FlutterResult _Nonnull)result {
if (@available(iOS 10.0, *)) {
UNUserNotificationCenter *center =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,44 +293,6 @@ class FlutterLocalNotificationsPlugin {
await FlutterLocalNotificationsPlatform.instance.cancelAll();
}

/// Schedules a notification to be shown at the specified date and time.
///
/// The [androidAllowWhileIdle] parameter determines if the notification
/// should still be shown at the exact time even when the device is in a
/// low-power idle mode.
@Deprecated('Deprecated due to problems with time zones. Use zonedSchedule '
'instead.')
Future<void> schedule(
int id,
String? title,
String? body,
DateTime scheduledDate,
NotificationDetails notificationDetails, {
String? payload,
@Deprecated('Deprecated in favor of the androidScheduleMode parameter')
bool androidAllowWhileIdle = false,
AndroidScheduleMode? androidScheduleMode,
}) async {
if (kIsWeb) {
return;
}
if (defaultTargetPlatform == TargetPlatform.android) {
await resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()!
.schedule(id, title, body, scheduledDate, notificationDetails.android,
payload: payload,
scheduleMode: _chooseScheduleMode(
androidScheduleMode, androidAllowWhileIdle));
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
await resolvePlatformSpecificImplementation<
IOSFlutterLocalNotificationsPlugin>()
?.schedule(id, title, body, scheduledDate, notificationDetails.iOS,
payload: payload);
} else if (defaultTargetPlatform == TargetPlatform.macOS) {
throw UnimplementedError();
}
}

/// Schedules a notification to be shown at the specified date and time
/// relative to a specific time zone.
///
Expand Down Expand Up @@ -374,7 +336,7 @@ class FlutterLocalNotificationsPlugin {
required UILocalNotificationDateInterpretation
uiLocalNotificationDateInterpretation,
@Deprecated('Deprecated in favor of the androidScheduleMode parameter')
bool androidAllowWhileIdle = false,
bool androidAllowWhileIdle = false,
AndroidScheduleMode? androidScheduleMode,
String? payload,
DateTimeComponents? matchDateTimeComponents,
Expand Down Expand Up @@ -439,7 +401,7 @@ class FlutterLocalNotificationsPlugin {
NotificationDetails notificationDetails, {
String? payload,
@Deprecated('Deprecated in favor of the androidScheduleMode parameter')
bool androidAllowWhileIdle = false,
bool androidAllowWhileIdle = false,
AndroidScheduleMode? androidScheduleMode,
}) async {
if (kIsWeb) {
Expand Down Expand Up @@ -476,75 +438,6 @@ class FlutterLocalNotificationsPlugin {
? AndroidScheduleMode.exactAllowWhileIdle
: AndroidScheduleMode.exact);

/// Shows a notification on a daily interval at the specified time.
@Deprecated(
'Deprecated due to problems with time zones. Use zonedSchedule instead '
'by passing a date in the future with the same time and pass '
'DateTimeComponents.time as the value of the '
'matchDateTimeComponents parameter.')
Future<void> showDailyAtTime(
int id,
String? title,
String? body,
Time notificationTime,
NotificationDetails notificationDetails, {
String? payload,
}) async {
if (kIsWeb) {
return;
}
if (defaultTargetPlatform == TargetPlatform.android) {
await resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.showDailyAtTime(
id, title, body, notificationTime, notificationDetails.android,
payload: payload);
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
await resolvePlatformSpecificImplementation<
IOSFlutterLocalNotificationsPlugin>()
?.showDailyAtTime(
id, title, body, notificationTime, notificationDetails.iOS,
payload: payload);
} else if (defaultTargetPlatform == TargetPlatform.macOS) {
throw UnimplementedError();
}
}

/// Shows a notification on weekly interval at the specified day and time.
@Deprecated(
'Deprecated due to problems with time zones. Use zonedSchedule instead '
'by passing a date in the future with the same day of the week and time '
'as well as passing DateTimeComponents.dayOfWeekAndTime as the value of '
'the matchDateTimeComponents parameter.')
Future<void> showWeeklyAtDayAndTime(
int id,
String? title,
String? body,
Day day,
Time notificationTime,
NotificationDetails notificationDetails, {
String? payload,
}) async {
if (kIsWeb) {
return;
}
if (defaultTargetPlatform == TargetPlatform.android) {
await resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.showWeeklyAtDayAndTime(id, title, body, day, notificationTime,
notificationDetails.android,
payload: payload);
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
await resolvePlatformSpecificImplementation<
IOSFlutterLocalNotificationsPlugin>()
?.showWeeklyAtDayAndTime(
id, title, body, day, notificationTime, notificationDetails.iOS,
payload: payload);
} else if (defaultTargetPlatform == TargetPlatform.macOS) {
throw UnimplementedError();
}
}

/// Returns a list of notifications pending to be delivered/shown.
Future<List<PendingNotificationRequest>> pendingNotificationRequests() =>
FlutterLocalNotificationsPlatform.instance.pendingNotificationRequests();
Expand Down
Loading

0 comments on commit 6f5c3e8

Please sign in to comment.