ios – 如何检测可 *** 作通知的触发日期

ios – 如何检测可 *** 作通知的触发日期,第1张

概述我的应用程序中有提醒.我每天都会重复通知.现在可以在我的通知中心看到多个通知.由于它是可 *** 作的通知,用户可以点击“是”或“否”. 我听了它如下: import Foundationimport UserNotificationsimport UserNotificationsUIclass NotificationSetup: NSObject, UNUserNotificationCe 我的应用程序中有提醒.我每天都会重复通知.现在可以在我的通知中心看到多个通知.由于它是可 *** 作的通知,用户可以点击“是”或“否”.

我听了它如下:

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”

解决方法@H_403_35@ UIlocalnotification有fireDate属性.你可以使用它.另外,为了支持iOS7,您需要使用UIlocalnotification而不是UNUserNotificationCenterDelegate

发起本地通知

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 – 如何检测可 *** 作通知的触发日期所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1002273.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存