首页 > 解决方案 > 如何在 Flutter 中为 iOS 创建闹钟应用

问题描述

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

标签: iosflutter

解决方案


我使用颤振本地通知包找到了解决该问题的方法,您可以在将来安排通知,它将在前台、后台和应用程序终止时工作,因此涵盖所有情况并在我的场景中完美工作。如果您需要为 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);

推荐阅读