我听了它如下:
import Foundationimport UserNotificationsimport UserNotificationsUIclass NotificationSetup: NSObject,UNUserNotificationCenterDelegate{ let requestIDentifIEr = "SampleRequest" let salahTimeArr = [ [ "salahname": "Fajar","time" : DateComponents.init( hour: 7,minute: 0 )],[ "salahname": "Zuhar","time" : DateComponents.init( hour: 14,[ "salahname": "Asar","time" : DateComponents.init( hour: 18,[ "salahname": "Maghrib","time" : DateComponents.init( hour: 19,minute: 30 )],[ "salahname": "Isha","time" : DateComponents.init( hour: 22,minute: 0 ) ] ] //============================================================ func createNotificationcategory() { let center = UNUserNotificationCenter.current() center.requestAuthorization(options: [.alert,.sound]) { (granted,error) in let actionYes = UNNotificationAction(IDentifIEr: "yes",Title: "Yes",options: []) let actionNo = UNNotificationAction(IDentifIEr: "no",Title: "No",options: []) let category = UNNotificationcategory(IDentifIEr: "SalahOfferedActionableNotification",actions: [actionYes,actionNo],intentIDentifIErs: [],options: []) UNUserNotificationCenter.current().setNotificationCategorIEs([category]) } } //---------------------------------- func setNotifications() { self.createNotificationcategory() if ( UserDefaults.standard.bool(forKey: "isNotificationSet") == false ) { for salahDict in salahTimeArr { print(salahDict["salahname"]) let content = UNMutableNotificationContent() content.Title = "DID you offer" content.subTitle = salahDict["salahname"] as! String content.body = "Its Fard!" content.sound = UNNotificationSound.default() content.categoryIDentifIEr = "SalahOfferedActionableNotification" //------------------------ let date = salahDict["time"] as! DateComponents let trigger = UNCalendarNotificationTrigger.init(dateMatching: date,repeats: true) let request = UNNotificationRequest(IDentifIEr: requestIDentifIEr,content: content,trigger: trigger) //------------------------ let notificationSingletonObj = UNUserNotificationCenter.current() notificationSingletonObj.delegate = self //------------------------ notificationSingletonObj.add(request) { (error) in if (error != nil) { print(error?.localizedDescription) } } } UserDefaults.standard.set( true,forKey: "isNotificationSet" ) } } //============================================================ func userNotificationCenter(_ center: UNUserNotificationCenter,dIDReceive response: UNNotificationResponse,withCompletionHandler completionHandler: @escaPing () -> VoID) { let salahname = response.notification.request.content.subTitle let date = response.notification.date if response.actionIDentifIEr == "yes" { print("User tapped 'Yes' button on notification for Salah: \(salahname)") UserDefaults.standard.set( true,forKey: salahname ) Calculation().addSalah(forSalah : salahname,offered: 1 ) userDefaults.set( Date(),forKey: "dataCapturedForDate") } }}
let date = response.notification.date
但正如苹果文档所说,它支持iOS 10&后来.但我希望支持到iOS7.
请参考通知中心图像清楚地理解.
我有相同的标题,描述和所有通知信息类似.我想检测用户点击的通知.天气是星期一的通知或星期二的通知.天气是“A”或“B”
发起本地通知
let localnotification = UIlocalnotification()let fireDate = Date()localnotification.fireDate = fireDatelocalnotification.alertbody = "Your alert message"localnotification.repeatInterval = .dayUIApplication.shared.schedulelocalnotification(localnotification)
在您的应用代表中
func application(_ application: UIApplication,dIDReceive notification: UIlocalnotification) { notification.fireDate}总结
以上是内存溢出为你收集整理的ios – 如何检测可 *** 作通知的触发日期全部内容,希望文章能够帮你解决ios – 如何检测可 *** 作通知的触发日期所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)