ios - iOS8-iOS9设置提醒/闹钟

标签 ios swift uilocalnotification alarm eventkit

主要问题:如果我想在我的应用程序中为任务附加截止日期,我应该使用本地通知、警报或提醒吗?我希望他们在截止日期到来时即使应用程序未运行也能收到通知。

我找到了 this关于使用它说可以的 UILocalNotification 的教程:

gives us the ability to cast notifications to a user without running the application

然而,它是六年前写的,并且还声明这是在 iOS4 中引入的。我知道 5 个 iOS 版本有很多变化。

我也是read ,或者,我可以使用 Event Kit。然而,这似乎比 UILocalNotification 更复杂。

最后,我可能会使用当前日期/时间和提醒日期/时间和 create a timer倒计时。

因此,如果我只想将截止日期附加到我应用程序中的任务(它们不需要显示在提醒或日历中),最好的方法是什么?为什么?

最佳答案

我发现以下 block code here .这也是关于如何在应用程序中创建事件的一个很好的教程。

var notification = UILocalNotification()
notification.alertBody = "Todo Item \"\(item.title)\" Is Overdue" // text that will be displayed in the notification
notification.alertAction = "open" // text that is displayed after "slide to..." on the lock screen - defaults to "slide to view"
notification.fireDate = item.deadline // todo item due date (when notification will be fired)
notification.soundName = UILocalNotificationDefaultSoundName // play default sound
notification.userInfo = ["UUID": item.UUID, ] // assign a unique identifier to the notification so that we can retrieve it later
notification.category = "TODO_CATEGORY"
UIApplication.sharedApplication().scheduleLocalNotification(notification)

关于ios - iOS8-iOS9设置提醒/闹钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34676669/

相关文章:

iphone - 计划的本地通知未存储在 scheduledLocalNotification 数组中

ios - 应用程序在前台时是否可以不触发本地通知?

ios - Sprite 一旦超过屏幕高度就会自行移除

ios - 在 Xcode 9 中添加 block 注释的键盘快捷方式?

ios - 使用 url 方案将标记添加到 ios 中的谷歌地图

swift - "error: Couldn' t IRGen expression, no additional error"on Xcode 10.1 的解决方案是什么?

ios - View 不会在 SwiftUI 的 ForEach 内部更新

ios - Sprite 跟随不同的 Sprite 延迟

ios - 将项目从 Objective C 移动到 Swift 时,类型 'AnyHashable' 的值没有下标

iphone - 更改已设置的 UILocalNotification 的 soundName