
// UISwitch用于季度通知
@IBAction func quarterlyFrequencyTapped(_ sender: UISwitch) {if quarterlyFrequency.isOn == true { firstQuarter(); secondQuarter(); thirdQuarter(); fourthQuarter() print("quarterly frequency is \(quarterlyFrequency.isOn)")} else { removeQuarterlyNotification() print("quaterly frequency is \(monthlyFrequency.isOn)") }} //所有四个季度的功能
func firstQuarter() { let firstQuarterContent = UNMutableNotificationContent() firstQuarterContent.Title = "First Quarter" firstQuarterContent.subTitle = "Some string" firstQuarterContent.body = "Some other string" var firstQuarterDate = DateComponents() firstQuarterDate.month = 3 firstQuarterDate.day = 11 firstQuarterDate.hour = 19 firstQuarterDate.minute = 20 let firstQuarterTrigger = UNCalendarNotificationTrigger(dateMatching: firstQuarterDate,repeats: true) let firstQuarterRequestIDentifIEr = "Quarterly" let firstQuarterRequest = UNNotificationRequest(IDentifIEr: firstQuarterRequestIDentifIEr,content: firstQuarterContent,trigger: firstQuarterTrigger) UNUserNotificationCenter.current().add(firstQuarterRequest,withCompletionHandler: nil)}func secondQuarter() { let secondQuarterContent = UNMutableNotificationContent() secondQuarterContent.Title = "Second Quarter" secondQuarterContent.subTitle = "Some string" secondQuarterContent.body = "Some other string" var secondQuarterDate = DateComponents() secondQuarterDate.month = 3 secondQuarterDate.day = 11 secondQuarterDate.hour = 19 secondQuarterDate.minute = 21 let secondQuarterTrigger = UNCalendarNotificationTrigger(dateMatching: secondQuarterDate,repeats: true) let secondQuarterRequestIDentifIEr = "Quarterly" let secondQuarterRequest = UNNotificationRequest(IDentifIEr: secondQuarterRequestIDentifIEr,content: secondQuarterContent,trigger: secondQuarterTrigger) UNUserNotificationCenter.current().add(secondQuarterRequest,withCompletionHandler: nil)}func thirdQuarter() { let thirdQuarterContent = UNMutableNotificationContent() thirdQuarterContent.Title = "Third Quarter" thirdQuarterContent.subTitle = "Some string" thirdQuarterContent.body = "Some other string" var thirdQuarterDate = DateComponents() thirdQuarterDate.month = 3 thirdQuarterDate.day = 11 thirdQuarterDate.hour = 19 thirdQuarterDate.minute = 22 let thirdQuarterTrigger = UNCalendarNotificationTrigger(dateMatching: thirdQuarterDate,repeats: true) let thirdQuarterRequestIDentifIEr = "Quarterly" let thirdQuarterRequest = UNNotificationRequest(IDentifIEr: thirdQuarterRequestIDentifIEr,content: thirdQuarterContent,trigger: thirdQuarterTrigger) UNUserNotificationCenter.current().add(thirdQuarterRequest,withCompletionHandler: nil)}func fourthQuarter() { let fourthQuarterContent = UNMutableNotificationContent() fourthQuarterContent.Title = "Fourth Quarter" fourthQuarterContent.subTitle = "Some string" fourthQuarterContent.body = "Some other string" var fourthQuarterDate = DateComponents() fourthQuarterDate.month = 3 fourthQuarterDate.day = 11 fourthQuarterDate.hour = 19 fourthQuarterDate.minute = 23 let fourthQuarterTrigger = UNCalendarNotificationTrigger(dateMatching: fourthQuarterDate,repeats: true) //let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60,repeats: true) let fourthQuarterRequestIDentifIEr = "Quarterly" let fourthQuarterRequest = UNNotificationRequest(IDentifIEr: fourthQuarterRequestIDentifIEr,content: fourthQuarterContent,trigger: fourthQuarterTrigger) UNUserNotificationCenter.current().add(fourthQuarterRequest,withCompletionHandler: nil)}解决方法 我认为你在iOS10上,你正在使用UserNotifications框架吗? 您的标识符很可能具有相同的标识符,并且每个标识符都会更新以前的通知.
原因标识符用于帮助您更新具有相同标识符的先前通知.例如,您发送通知以将分数从0-0更新为0-1.而不是在屏幕上有2个通知,你现在只有一个.
您的修复是为每个使用不同的标识符.
有关更多信息,请参阅此moment以获取WWDC视频
编辑后更新:正如我所说的……所有通知都以“季度”作为标识符.给他们每个人一个单独的名字.
总结以上是内存溢出为你收集整理的swift – 为什么只调用我的上一个本地通知函数?全部内容,希望文章能够帮你解决swift – 为什么只调用我的上一个本地通知函数?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)