Find list of Local Notification the app has already set

后端 未结 8 1863
盖世英雄少女心
盖世英雄少女心 2020-12-01 05:37

My app allows users to set a number of reminders in the future. When the app lauches I want to know what reminders (notifications) have already been set.

Can I read

8条回答
  •  鱼传尺愫
    2020-12-01 05:42

    For Swift 3.0 and Swift 4.0

    don't forget to do import UserNotifications

    This is working for iOS10+ and watchOS3+ since the class UNUserNotificationCenter is not available for older versions (link)

    let center = UNUserNotificationCenter.current()
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    
        center.getPendingNotificationRequests { (notifications) in
            print("Count: \(notifications.count)")
            for item in notifications {
              print(item.content)
            }
        }
    }
    

提交回复
热议问题