如何在 Flutter 中为 iOS 创建闹钟应用

Posted

技术标签:

【中文标题】如何在 Flutter 中为 iOS 创建闹钟应用【英文标题】:How to create alarm app in flutter for ios 【发布时间】:2020-05-20 04:29:39 【问题描述】:

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

【问题讨论】:

【参考方案1】:

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

【讨论】:

以上是关于如何在 Flutter 中为 iOS 创建闹钟应用的主要内容,如果未能解决你的问题,请参考以下文章