1

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) 
 } 
}
sonle
10.4k3 gold badges19 silver badges33 bronze badges
asked Jan 9, 2024 at 19:51
3
  • Have you tried to put a debug point on didReceive response? Did it execute when you tapped on the notification? Commented Jan 10, 2024 at 0:57
  • I tried debug breakpoint but don't get error. When you tapped notification open my apps first page. Commented Jan 10, 2024 at 16:52
  • Does anyone else have any ideas? Commented Jan 10, 2024 at 19:48

1 Answer 1

0

I solve this code.

 func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
 
 
 if response.notification.request.identifier == "deneme" {
 if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
 let window = windowScene.windows.first {
 
 let storyboard = UIStoryboard(name: "Main", bundle: nil)
 let viewController = storyboard.instantiateViewController(withIdentifier: "burcListView") as! ViewController
 viewController.choosenTime = "0"
 window.rootViewController = viewController
 }
 
 }
 
 completionHandler()
 }
answered Jan 11, 2024 at 12:28
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.