小编Jav*_*ras的帖子

使用开关启用和禁用本地通知(swift 3)

我正在制作我的第一个应用程序,其中一个功能是待办事项列表。我有一个开关,当它关闭时禁用本地通知,当它打开时,它应该在开关打开时启用它们。我使用 保存开关状态UserDefaults,通知确实出现,但是,即使我指定它们应该它们也不会重复。现在我将通知设置为每 60 秒重复一次以进行测试,但是当它起作用时将需要两天时间。只要开关打开,如何使通知重复?我的开关代码:

@IBOutlet weak var switchout: UISwitch!

@IBAction func notifswitch(_ sender: Any) {
print ("hello")
    if switchout.isOn
    {
        if #available(iOS 10.0, *), list.isEmpty == false {

            let content = UNMutableNotificationContent()
            content.title = "You have tasks to complete!"
            content.subtitle = ""
            content.body = "Open the task manager to see which tasks 
need completion"
            let alarmTime = Date().addingTimeInterval(60) 
            let components = Calendar.current.dateComponents([.weekday, 
.hour, .minute], from: alarmTime)
            let trigger = UNCalendarNotificationTrigger(dateMatching: 
components, repeats: true)
            let …
Run Code Online (Sandbox Code Playgroud)

uiswitch ios uilocalnotification swift3

2
推荐指数
1
解决办法
2837
查看次数

标签 统计

ios ×1

swift3 ×1

uilocalnotification ×1

uiswitch ×1