如何在 ios 的 flutter 中创建闹钟应用

use*_*316 6 ios flutter

我想要的是设置一个时间并在该特定时间运行后台进程(dart),就像任何基本的警报应用程序一样。我搜索了很多,但找不到任何对 iOS 有用的东西。我需要它在 dart 中,因为我无法使用平台通道。

use*_*316 9

我找到了使用flutter 本地通知包解决该问题的方法,您可以在将来安排通知,它可以在前台、后台以及应用程序终止时工作,因此涵盖了所有情况,并且在我的场景中完美工作。如果您需要为 IOS 做闹钟或提醒之类的事情,它会为您完成工作。

var scheduledNotificationDateTime =
    DateTime.now().add(Duration(seconds: 5));
var androidPlatformChannelSpecifics =
    AndroidNotificationDetails('your other channel id',
        'your other channel name', 'your other channel description');
var iOSPlatformChannelSpecifics =
    IOSNotificationDetails();
NotificationDetails platformChannelSpecifics = NotificationDetails(
    androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.schedule(
    0,
    'scheduled title',
    'scheduled body',
    scheduledNotificationDateTime,
    platformChannelSpecifics);
Run Code Online (Sandbox Code Playgroud)