
这是用于注册本地通知>>>
func registerLocal() { let center = UNUserNotificationCenter.current() center.requestAuthorization(options: [.alert,.badge,.sound]) { (granted,error) in if granted { print("Yay!") } else { print("D'oh") } }} 和此功能来安排本地通知>>>
func scheduleLocal() { registerCategorIEs() let center = UNUserNotificationCenter.current() // not required,but useful for testing! center.removeAllPendingNotificationRequests() let content = UNMutableNotificationContent() content.Title = "good morning" content.body = "ttt123" content.categoryIDentifIEr = "alarm" content.userInfo = ["customData": "fizzbuzz"] content.sound = UNNotificationSound.default() var dateComponents = DateComponents() dateComponents.hour = 23 dateComponents.minute = 18 let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents,repeats: true) let request = UNNotificationRequest(IDentifIEr: UUID().uuIDString,content: content,trigger: trigger) center.add(request)}func registerCategorIEs() { let center = UNUserNotificationCenter.current() center.delegate = self let show = UNNotificationAction(IDentifIEr: "show",Title: "Tell me more…",options: .foreground) let category = UNNotificationcategory(IDentifIEr: "alarm",actions: [show],intentIDentifIErs: []) center.setNotificationCategorIEs([category])}func userNotificationCenter(_ center: UNUserNotificationCenter,dIDReceive response: UNNotificationResponse,withCompletionHandler completionHandler: @escaPing () -> VoID) { // pull out the burIEd userInfo dictionary let userInfo = response.notification.request.content.userInfo if let customData = userInfo["customData"] as? String { print("Custom data received: \(customData)") switch response.actionIDentifIEr { case UNNotificationDefaultActionIDentifIEr: // the user swiped to unlock; do nothing print("Default IDentifIEr") case "show": print("Show more information…") break default: break } } // you need to call the completion handler when you're done completionHandler()} 现在我如何使用此代码与iOS 10和不同时间的多个本地通知
谢谢 .
只需确保您在UNNotificationRequest(IDentifIEr:,content:,trigger :)函数中传递的标识符对于每个通知都是不同的.
希望这可以帮助. 总结
以上是内存溢出为你收集整理的通知 – 如何实现多个本地通知而不是swift 3的单个通知全部内容,希望文章能够帮你解决通知 – 如何实现多个本地通知而不是swift 3的单个通知所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)