set local notification and get pending notification and remove local notification in swift

how to set local notification in swift

        let content = UNMutableNotificationContent()
        content.title = "notification title"
        content.categoryIdentifier = "identifier"
        content.body = "notification body"
        content.sound = UNNotificationSound.default
        
        let triggerDateComponent = Calendar.current.dateComponents([.day, .hour, .minute], from: Date().addHours(5))
        
        let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDateComponent, repeats: false)
        
        let request = UNNotificationRequest(identifier: "notification identifier", content: content, trigger: trigger)
        
        UNUserNotificationCenter.current().add(request, withCompletionHandler: { (error) in
           if error != nil {
               print(error!)
               
           } else {
               print("\(request.description)")
           }
       })


how to get pending notification in swift

center.getPendingNotificationRequests { (notifications) in
            print("Count: \(notifications.count)")
                
            for item in notifications {
                
                let id = item.identifier
                let time = item.content
                let categoryId = time.categoryIdentifier
                print(time)
                print("id: \(id)")
                guard let trigger = item.trigger as? UNCalendarNotificationTrigger else { return }
                var day = trigger.dateComponents.weekday
                let nextFireDate = trigger.nextTriggerDate()
                let title = item.content.body
                }
   }

how to remove notification in swift

UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: ["notification identifire"])

Clickable attributed text in swift

for example if you set privacy policy text in single line with multiple click in swift

let attributedString = NSMutableAttributedString(string: "By continueing you agree terms and conditions and the privacy policy")

attributedString.addAttribute(.link, value: "<a href="https://pathanikbal.wordpress.com">https://yourlink</a>", range: (attributedString.string as NSString).range(of: "terms and conditions"))

attributedString.addAttribute(.link, value: "https://pixsterstudio.com/terms-of-use.html", range: (attributedString.string as NSString).range(of: "privacy policy"))

textview.backgroundColor = UIColor(named: "newBGColor")
textview.textAlignment = .center
textview.linkTextAttributes = [ NSAttributedString.Key.foregroundColor: UIColor.blue]
textview.attributedText = attributedString
textview.delegate = self
textview.isSelectable = true
textview.isEditable = false
textview.delaysContentTouches = false
textview.isScrollEnabled = false
textview.font = UIFont(name: "AvenirNext-Regular", size: 10)


func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {

            if URL.scheme == "terms" {
                print("---- TERMS & CONDITION -----")
                return false

            } else  if URL.scheme == "privacy"{
                print("---- PRIVACY & POLICY -----")
                 return false
            }
            return true
 }