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
0
votes
1 answer

Scheduled NSNotification (Instead of UILocalNotification)... Swift solutions?

My app (prefix "AAS") is basically a game where users lose points every day they don't play. I use UILocalNotifications to alert the user that they've lost points, and invite them back to play. One of my view controllers displays when the points…
jperl
  • 1,066
  • 7
  • 14
0
votes
1 answer

nsnotification approach for session inactivity in objective c

In sesssion inactivity implementation for my project. I have created a NSNotification in RootViewController class of project. - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]…
Nitya
  • 449
  • 1
  • 8
  • 24
0
votes
0 answers

Detecting Rotation of UIView in Swift

I have created a custom view that inherits from UIView. I really need to be able to detect the rotation in my custom view class. I have already searched online and tried…
pls
  • 1,522
  • 2
  • 21
  • 41
0
votes
1 answer

NSNotification addObserver of keyboard event + UIButton type triggers auto animation?

I was trying to add a button vertically on top of keyboard after the keyboard showed. The problem comes that the added button flies from top left corner to my target location, without any animation code, when I did the following two things: I added…
0
votes
1 answer

Executing a selector after receiving NSNotification calls my view controller's deinit

My view controller's deinit function is called each time I receive a NSNotification and execute the corresponding selector!!! Here's my view controller's code: override func viewDidLoad() { super.viewDidLoad() …
Abdurrahman
  • 6,306
  • 3
  • 19
  • 20
0
votes
1 answer

using NSNotification with CoreData

I have an TO-DO list app that I would like each entry in the app to have the ability to have a notification set for it. I would also like the user to have the ability to change the time that notification is schedule to deploy. My question is what…
icekomo
  • 9,328
  • 7
  • 31
  • 59
0
votes
1 answer

Unit test on a NSNotification which is sent ansynchronous by a NSTimer

Since a few days I try to figure out how to test my API with GHUnit. Now I came to the problem to test this: The API gets some several inputs, the CUT does something and starts an NSTimer. After the timer fired, it sends out an NSNotification with…
0
votes
3 answers

Spotlight search doesn't work when app not running

I want to tell first UIViewController that Spotlight opened it. I try to make it by NSNotificationCenter. But I tried several methods and they don't it when I make my key like "spotlightOpen". When I use standard name like…
Alexander Khitev
  • 6,417
  • 13
  • 59
  • 115
0
votes
1 answer

Proper way to listen to NSNotifications

Is it proper, if I have 2 notifications on a view controller to have 2 observers like so: [NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotifications:) name:@"note1" object:nil]; [NSNotificationCenter defaultCenter]…
cdub
  • 24,555
  • 57
  • 174
  • 303
0
votes
2 answers

NSNotifications only being sent within the same object

Hey there, so I've got an NSObject subclass sending out a message via the notification center, and I'm sending out my notifications out to the object nil but the only object that can receive notifications is the one sending them I've got two…
orta
  • 4,225
  • 1
  • 26
  • 34
0
votes
1 answer

Animation not working when it comes from a notification

Working in an app with Objective-C I got the next problem: I have a code that executes an animation in a UIViewController that is called with input from the user and also when a push notification comes from other user using this app. The matter is…
Cacique
  • 11
  • 3
0
votes
2 answers

Should NSNotificationCenter selector be with or without an NSNotification object

I'm doing some code cleanup and am wondering if there is an official or unofficial standard as to what option below should be preferable. The basic issue is that I have to do some view change logic. This code should be called both in awakeFromNib…
xizor
  • 1,554
  • 2
  • 16
  • 35
0
votes
1 answer

NSRecursivelock v NSNotification performance

So I was using an array to hold objects, then iterating over them to call a particular method. As the objects in this array could be enumerated/mutated on different threads I was using an NSRecursiveLock. I then realised that as this method is…
0
votes
1 answer

addObserver in main thread using GCD and post notification in a global thread but the method never be called

- (void)viewDidLoad { [super viewDidLoad]; //NSNotificationCenter第一坑 NSLog(@"current thread:%@",[NSThread currentThread]); //在主线程中注册通知并转发消息 //add observer in main thread and deal in main thread …
0
votes
0 answers

How to pass NSManagedObject to userInfo of UILocalNotification

I'm trying to pass an NSManagedObject to userInfo of UILocalNotification, something like: NSManagedObject *obj = ...; UILocalNotification* localNotification = [[[UILocalNotification alloc] init] autorelease]; localNotification.userInfo =…
Yuwen Yan
  • 4,777
  • 10
  • 33
  • 63