Class: NSNotificationCenter

Inherits:
NSObject show all

Overview

An NSNotificationCenter object (or simply, notification center) provides a mechanism for broadcasting information within a program. An NSNotificationCenter object is essentially a notification dispatch table.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Class Method Details

+ (Object) defaultCenter

Returns the process’s default notification center.

Returns:

  • (Object)

    The current process’s default notification center, which is used for system notifications.

Instance Method Details

- (Object) addObserver(notificationObserver, selector:notificationSelector, name:notificationName, object:notificationSender)

Adds an entry to the receiver’s dispatch table with an observer, a notification selector and optional criteria: notification name and sender. Be sure to invoke removeObserver: or removeObserver:name:object: before notificationObserver or any object specified in addObserver:selector:name:object: is deallocated.

Parameters:

  • notificationObserver (Object)

    Object registering as an observer. This value must not be nil.

  • notificationSelector (Symbol)

    Selector that specifies the message the receiver sends notificationObserver to notify it of the notification posting. The method specified by notificationSelector must have one and only one argument (an instance of NSNotification).

  • notificationName (String)

    The name of the notification for which to register the observer; that is, only notifications with this name are delivered to the observer.If you pass nil, the notification center doesn’t use a notification’s name to decide whether to deliver it to the observer.

  • notificationSender (Object)

    The object whose notifications the observer wants to receive; that is, only notifications sent by this sender are delivered to the observer.If you pass nil, the notification center doesn’t use a notification’s sender to decide whether to deliver it to the observer.

Returns:

- (Object) addObserverForName(name, object:obj, queue:queue, usingBlock:block)

Adds an entry to the receiver’s dispatch table with a notification queue and a block to add to the queue, and optional criteria: notification name and sender. If a given notification triggers more than one observer block, the blocks may all be executed concurrently with respect to one another (but on their given queue or on the current thread).The following example shows how you can register to receive locale change notifications.To unregister observations, you pass the object returned by this method to removeObserver:. You must invoke removeObserver: or removeObserver:name:object: before any object specified by addObserverForName:object:queue:usingBlock: is deallocated.

Parameters:

  • name (String)

    The name of the notification for which to register the observer; that is, only notifications with this name are used to add the block to the operation queue.If you pass nil, the notification center doesn’t use a notification’s name to decide whether to add the block to the operation queue.

  • obj (Object)

    The object whose notifications you want to add the block to the operation queue.If you pass nil, the notification center doesn’t use a notification’s sender to decide whether to add the block to the operation queue.

  • queue (NSOperationQueue)

    The operation queue to which block should be added.If you pass nil, the block is run synchronously on the posting thread.

  • block (Object)

    The block to be executed when the notification is received.The block is copied by the notification center and (the copy) held until the observer registration is removed. The block takes one argument:notificationThe notification.

  • notification (NSNotification)

    The notification.

Returns:

  • (Object)

    An opaque object to act as the observer.

- (Object) postNotification(notification)

Posts a given notification to the receiver. You can create a notification with the NSNotification class method notificationWithName:object: or notificationWithName:object:userInfo:. An exception is raised if notification is nil.

Parameters:

  • notification (NSNotification)

    The notification to post. This value must not be nil.

Returns:

- (Object) postNotificationName(notificationName, object:notificationSender)

Creates a notification with a given name and sender and posts it to the receiver. This method invokes postNotificationName:object:userInfo: with a userInfo argument of nil.

Parameters:

  • notificationName (String)

    The name of the notification.

  • notificationSender (Object)

    The object posting the notification.

Returns:

- (Object) postNotificationName(notificationName, object:notificationSender, userInfo:userInfo)

Creates a notification with a given name, sender, and information and posts it to the receiver. This method is the preferred method for posting notifications.

Parameters:

  • notificationName (String)

    The name of the notification.

  • notificationSender (Object)

    The object posting the notification.

  • userInfo (Hash)

    Information about the the notification. May be nil.

Returns:

- (Object) removeObserver(notificationObserver)

Removes all the entries specifying a given observer from the receiver’s dispatch table. Be sure to invoke this method (or removeObserver:name:object:) before notificationObserver or any object specified in addObserver:selector:name:object: is deallocated.The following example illustrates how to unregister someObserver for all notifications for which it had previously registered:

Parameters:

  • notificationObserver (Object)

    The observer to remove. Must not be nil.

Returns:

- (Object) removeObserver(notificationObserver, name:notificationName, object:notificationSender)

Removes matching entries from the receiver’s dispatch table. Be sure to invoke this method (or removeObserver:) before the observer object or any object specified in addObserver:selector:name:object: is deallocated.

Parameters:

  • notificationObserver (Object)

    Observer to remove from the dispatch table. Specify an observer to remove only entries for this observer. Must not be nil, or message will have no effect.

  • notificationName (String)

    Name of the notification to remove from dispatch table. Specify a notification name to remove only entries that specify this notification name. When nil, the receiver does not use notification names as criteria for removal.

  • notificationSender (Object)

    Sender to remove from the dispatch table. Specify a notification sender to remove only entries that specify this sender. When nil, the receiver does not use notification senders as criteria for removal.

Returns: