Questions tagged [nsnotification]

NSNotification is a class used to send messages to observing classes through NSNotificationCenter.

NSNotification is a class used to send messages to observing classes through NSNotificationCenter. Notifications must have a name and can be optionally associated with a specific object. If an object is provided, the notification is only delivered to a class that is also observing the exact same name and object.

To send a notification, use NSNotificationCenter's postNotification: (a convenience function postNotificationName:object:userInfo: also exists which creates a notification and posts it with a single call). Classes posting a notification can also include an optional userInfo parameter to pass an object to the receiving class.

For more information, see Apple's documentation for NSNotification and NSNotificationCenter.

312 questions
3
votes
3 answers

How to register for an NSNotification from a UILocalNotification?

I have a tabbar application and let's say that I want to switch to the second tab and popup an alert at 12:00, even if my application is not running. I got all the code for UILocalNotification working correctly, but then I thought that the best way…
phi
  • 10,634
  • 6
  • 53
  • 88
3
votes
2 answers

Notification fired twice even tho adding observer only once

I have two class which uses NSNotification to communicate with each other. Currently, i have an issue with notification being fired twice, i've double/triple/even more checked that observer is not added more then 1 time, notification not being…
Pratik Jamariya
  • 810
  • 1
  • 10
  • 35
3
votes
1 answer

Is postNotificationName guaranteed to dispatch immediately to listeners?

If i do [[NSNotificationCenter defaultCenter] postNotificationName:@"N" object:self]; NSLog(@"here"); The observer is notified synchronously before NSLog(@"here"); is executed... if all objects are on the same thread, is this guaranteed to be…
Zuzana Paulis
  • 941
  • 1
  • 8
  • 19
3
votes
1 answer

Coalescing NSNotifications

Is there any way when using coalescing notifications on NSNotificationQueues to control the time range? I would like to coalesce e.g. for the next second, but as I understand the options available it's either immediately or on next run loop…
ATV
  • 4,116
  • 3
  • 23
  • 42
3
votes
2 answers

NSNotification: Attempt to present UIAlertController on ViewController whose view is not in the window hierarchy

I'm trying to show a UIAlertController in my ViewController in a function that's been called via an NSNotification. However I'm getting the error: Attempt to present on
Sam Heather
  • 1,493
  • 3
  • 19
  • 42
3
votes
2 answers

How do I detect if keyboard is currently shown, if I transitioned from another view controller that was already showing the keyboard?

I have a view controller that makes a UITextField firstResponder on ViewWillAppear. Normally I could just rely on a UIKeyboardWillShow notification to detect if the keyboard has shown, but this won't trigger if I came into the current view…
Vadoff
  • 9,219
  • 6
  • 43
  • 39
3
votes
3 answers

when to call removeObserver for nsnotificationcenter

I have a view controller with a button action: @IBAction func MultiplayerButtonClick(sender: AnyObject) { NSNotificationCenter.defaultCenter().addObserver( self, selector:…
Abdul Ahmad
  • 9,673
  • 16
  • 64
  • 127
3
votes
1 answer

NSNotification for single object in swift

I have two text fields, topTextField and bottomTextField, at the top and bottom of the screen, respectively. bottomTextField hides behind the virtual keyboard when it comes up so to fix that I'm using NSNotification to listen for the virtual…
twp
  • 31
  • 3
3
votes
1 answer

UITextField subclass - subscribing to events

I've created a subclass of UITextField which has its own visual style and functionality. The functionality is to restrict the user to decimal currency values (for example, 3.50), but that's not really relevant because I know the algorithm I have…
Ryan Bobrowski
  • 2,641
  • 3
  • 31
  • 52
3
votes
1 answer

UIProgressView progress update very slow within AlamoFire (async) call

Inside an AlamoFire get request I'm trying to update my progress bar. Like so: alamofireManager.request(.GET, urlPath, parameters: params).responseJSON{(request,response,JSON,error) in ...... …
Boid
  • 1,161
  • 1
  • 11
  • 21
3
votes
1 answer

Reload navigationBar UIBarButtonItems

I've been trying to solve this issue, but I can't figure out how. I have a UIButton to which I need to add a UILabel as a subview. I need to update this UIButton because I don't have the number I need until a method is called through an…
3
votes
2 answers

NSNotification cannot find selector

I'm posting a notification via the default center, like so: NSNotificationCenter.defaultCenter().postNotificationName(ColorDidGetTappedNotification, object: self) I'm observing the notification in another instance like…
Youssef Moawad
  • 2,846
  • 5
  • 28
  • 50
3
votes
3 answers

Which is better, dispatching NSNotification on the main thread or handing the notification on the main thread

I understand that there may not be a right answer, but I was very curious to find out what people think about this issue or if there are pros and cons for the following approaches. First example dispatches the notification on the main thread and…
dfujiwara
  • 353
  • 2
  • 11
3
votes
1 answer

Mac os X - Capture Mail.app Notifications in Cocoa

I was trying to figure out a way how to capture notifications coming from - for example - the integrated mail.app. I was using the NSUserNotifications and acted as an observer but none of the Mail.app notifications were captured. Is there a way in…
3
votes
4 answers

how to find Login & logout events in mac?

I am fresher for this application development field. I am tried to get notifications during user login & logout events. I have tried with NSWorkSpaceNotifications, but it does not working for me. Can somebody help me…
RashmiG
  • 318
  • 1
  • 4
  • 11