Question

Is there any way to break on the NSNotificationCenter posting a Note with a certain name? I have a class that for some reason don't receive en expected note...

Edit for clarification:

I have added an observer for the MPMoviePlayerPlaybackDidFinishNotification, but for some reason it seems as if the Notification isn't sent as expected. A normal fault here is that my object for some reason has unsubscribed itself as an observer (even though I find my code on that part to look valid). So, my intention was whether or not it is possible to break on the NSNotificationCenter actually passing on a NotificationName of a certain type, in this case MPMoviePlayerPlaybackDidFinishNotification...

Was it helpful?

Solution

Add a breakpoint in Xcode with the name "-[NSNotificationCenter postNotification:]" using the box displayed in the screenshot. Just remember that this will stop for every notification posted, so you might want to have the debugger log the arguments and autocontinue.

OTHER TIPS

You can put break point in methods which you call for certain event. e.g.

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];

[nc addObserver:self selector:@selector(keyboardWillShow:) name: UIKeyboardWillShowNotification object:nil];
[nc addObserver:self selector:@selector(keyboardWillHide:) name: UIKeyboardWillHideNotification object:nil];

here you can use break point in keyboardWillShow and keyboardWillHide method which call on the time of keyboard events.

So you need to specify valid event name and valid object name.

In case of textfield as an object you use like this

NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];

[notificationCenter addObserver:self
                       selector:@selector (handle_TextFieldTextChanged:)
                           name:UITextFieldTextDidChangeNotification
                         object:self.lockTextField];

so i think you need to add notification in right way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top