Group Group Group Group Group Group Group Group Group

NotificationDelegate not working

#1

I have done as per the book, I have made NotificationDelegate and extracted out the functionality out of AppDelegate.

the line where it assigning:
center.delegate = self?.notificationDelegate

problem is this when I have above delegate method

 func userNotificationCenter(_ center: UNUserNotificationCenter,
                                    willPresent notification: UNNotification,
                                    withCompletionHandler completionHandler:
            @escaping (UNNotificationPresentationOptions) -> Void) 

and

func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void)

Are not being called.

but if I move those methods to AppDelegate and change assignment like.
center.delegate = self

I am not sure what is happening. I already check self?.notioficationDelegate have value.
Is there any other way I can troubleshoot it. I believe I am not missing anything. Am I?

#2

@gargoyle Can you please help with this when you get a chance? Thank you - much appreciated! :]

#3

It’s hard to be able to tell you what’s happening without being able to see the code. Have you compared your code to the chapter’s download materials? You can find the working code in the projects/final directory for that chapter.

#4

what else need to be taken care of except delegate.
If delegate is assigned to other object. why wouldn’t it call method.
yes code is same. I just like to type stuff from my hand rather not moving finger and see completed project.
What I am trying to ask is, if there is anything except setting the delegate?

#5

@gargoyle Do you have any feedback about this? Thank you - much appreciated! :]

#6

The only thing I can think of is that the delegate isn’t a strong reference and it’s getting garbage collected.

If you run the final project provided does that one work for you? That’ll at least tell us if something else is going on.