Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

How to redirect when local push notification clicked?

I build a horoscope app, its has a local push notification. I want to when clicked notification, redirect it to a specific page but don't. My app first page always opens.

my appDelegate File;

extension AppDelegate: UNUserNotificationCenterDelegate{
 
 func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
 let storyBoard = UIStoryboard(name: "Main", bundle: nil)
 
 if response.notification.request.identifier == "asd"{
 
 if let tappadView = storyBoard.instantiateViewController(withIdentifier: "deneme") as? detailView{
 
 self.window?.rootViewController = tappadView
 }
 
 
 }
 
 completionHandler()
 }
}

my local push functions;

 func chechPermission(){
 let notificationCenter = UNUserNotificationCenter.current()
 notificationCenter.getNotificationSettings { settings in
 switch settings.authorizationStatus{
 case .authorized:
 self.dispatchNotification()
 case .denied:
 return
 case .notDetermined:
 notificationCenter.requestAuthorization(options: [.alert, .sound]) { didAllow, error in
 if didAllow{
 self.dispatchNotification()
 }
 }
 default:
 return
 }
 }
 
 }
 
 
 func dispatchNotification(){
 let iddentifier = "asd"
 let userNotification = UNUserNotificationCenter.current()
 let content = UNMutableNotificationContent()
 content.title = "Hu huu"
 content.body = "Yeni Geldi Yorumlar..."
 content.sound = .default
 let hour = 22
 let minute = 29
 let isDaily = true
 
 
 let calender = Calendar.current
 var dateComponent = DateComponents(calendar: calender, timeZone: TimeZone.current)
 dateComponent.hour = hour
 dateComponent.minute = minute
 
 let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponent, repeats: isDaily)
 let request = UNNotificationRequest(identifier: iddentifier, content: content, trigger: trigger)
 
 userNotification.removePendingNotificationRequests(withIdentifiers: [iddentifier])
 userNotification.add(request) 
 } 
}

Answer*

Draft saved
Draft discarded
Cancel
1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. Commented Jan 11, 2024 at 21:49

lang-swift

AltStyle によって変換されたページ (->オリジナル) /