Post

Replies

Boosts

Views

Activity

How to get current user location title to display
My question is how do you get ahold of the current user location title when clicking a button so that it can display the title inside the search bar. I know that by calling locationManager.requestLocation() inside my button it will redirect the user to current location but that is all know how to do. I've tried calling locationManager.location?.description but i had no luck.
1
0
676
Mar ’22
How to Remove local pending notifications using uuidString as the identifier for UNNotificationRequest
As far as I know it is easy to remove all pending notifications by just calling method      UNUserNotificationCenter.current().removeAllPendingNotificationRequests(), and to remove specific reminder we just add the hard coded identifier to the method removePendingNotificationRequests(withIdentifiers: "identifier"). But I'm not trying to remove all notifications or some with a hardcoded identifier. How can I remove a notification using a uuidString as the identifier which creates a unique identifier every time a user creates a new notification. I would like to delete the specific notification with the swipe delete style. If i could get a code sample i would really appreciate it. Here is my code where create my notification and where I would like to delete it: public var completionL: ((String,String,String)->Void)?       @objc func saveButtonPressed(){           if let titleText = titleTextFieldL.text, !titleText.isEmpty,       let bodyText = bodyViewField.text, !bodyText.isEmpty,       let searchText = locationSearchBar.text, !searchText.isEmpty{               completionL?(titleText,bodyText,"\(segmentedControl.titleForSegment(at: segmentedControl.selectedSegmentIndex)!): \(searchText)")               if segmentedControl.selectedSegmentIndex == 0{         if let center = defaults.coordinate(forKey: "NCoordinates"){           let content = UNMutableNotificationContent()           content.title = titleText           content.body = bodyText           content.sound = .default           let uuidStringEntry = UUID().uuidString           let region = CLCircularRegion(center: center, radius: 300.0, identifier: uuidStringEntry)           region.notifyOnEntry = true           region.notifyOnExit = false           let trigger = UNLocationNotificationTrigger(region: region, repeats: false)           let notificationRequest = UNNotificationRequest(identifier: uuidStringEntry, content: content, trigger: trigger)           UNUserNotificationCenter.current().add(notificationRequest) { error in             if error != nil{               print("Error providing Arriving notification")             }else{                              print("Successfully provided Arriving notification")             }           }         }       }else if segmentedControl.selectedSegmentIndex == 1{         if let center = defaults.coordinate(forKey: "NCoordinates"){                       let content = UNMutableNotificationContent()           content.title = titleText           content.body = bodyText           content.sound = .default           let uuidStringExit = UUID().uuidString           let region = CLCircularRegion(center: center, radius: 300.0, identifier: uuidStringExit)           region.notifyOnEntry = false           region.notifyOnExit = true           let trigger = UNLocationNotificationTrigger(region: region, repeats: false)           let notificationRequest = UNNotificationRequest(identifier: uuidStringExit, content: content, trigger: trigger)           UNUserNotificationCenter.current().add(notificationRequest) { error in             if error != nil{               print("Error providing Leaving notification")             }else{               print("Succesfully provided Leaving notification")             }           }         }       }             }         }     } Method to delete it:     return .delete   }       func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {     if editingStyle == .delete{       tableView.beginUpdates()       context.delete(reminder[indexPath.row])       reminder.remove(at: indexPath.row)              tableView.deleteRows(at: [indexPath], with: .fade)               tableView.endUpdates()       saveData()     }   }
0
0
594
Mar ’22