how to implement multiple local notification not a single notification for swift 3

后端 未结 4 1319
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-15 17:03

i have use the single notification , and this is my code: this is for register the local notification>>>

    func registerLocal() {
    let center = UNUserNotifi         


        
4条回答
  •  遇见更好的自我
    2021-02-15 17:46

    Call this function with different parameters. Like i called when app goes background

      func applicationDidEnterBackground(_ application: UIApplication) {
    
            setNotification(time: 25,identifier: "notific2")
            setNotification(time: 50,identifier: "notific3")
            setNotification(time: 90,identifier: "notific4")
        }
    
    
      func setNotification (time : Int,identifier : String)
        {
            let content = UNMutableNotificationContent()
            content.title = "Don't forget"
            content.body = "Buy some milk"
            content.sound = UNNotificationSound.default()
            let trigger = UNTimeIntervalNotificationTrigger(timeInterval: TimeInterval(time),
                                                            repeats: false)
            let center = UNUserNotificationCenter.current()
            // Swift
            let request = UNNotificationRequest(identifier: identifier,
                                                content: content, trigger: trigger)
            center.add(request, withCompletionHandler: { (error) in
                if error != nil {
                    // Something went wrong
                }
            })
        }
    

提交回复
热议问题