nsnotifications

NSNotification not calling the selector

我的未来我决定 提交于 2019-12-13 05:36:38
问题 I am creating a NSNotification in appDelegate . - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkRegister:) name:@"checkRegister" object:nil]; return YES; } -(void)checkRegister:(NSNotification *) notification{ //Some code } And I am posting notification in some other class: -(void)connectionDidFinishLoading:(NSURLConnection *)connection { NSLog(@"DONE.

Registering a bool for a NSNotification

二次信任 提交于 2019-12-13 05:16:30
问题 I'm trying to wrap my head around NSNotification but can't seem to get it to work. Think I'm misunderstanding how to register for an notification. I have a bool as a property in my connection manager class. At initialisation I authenticate with a few servers and check if I can access an external URL (App will mainly be used on company intranet and an external connection isn't always possible) The BOOL property will be changed from YES to NO if it cannot access the connection and as this can

BOOL being reset to NO in init method

家住魔仙堡 提交于 2019-12-13 04:00:20
问题 I want to show a Now Playing button in a UINavigationController's bar. I have a class (NowPlayingManager) that I am using to keep track of whether an audio file is currently being played. I use a notification posted in another class (AudioViewController) to indicate playing status. AudioViewController creates an instance of the NowPlayingManager with alloc/init and releases it. In NowPlayingManager's target of the received notification I set NowPlayingManager's isNowPlaying Boolean to YES.

Enforcing that a class posts a particular NSNotification?

江枫思渺然 提交于 2019-12-13 03:42:50
问题 Is there any way to ensure that a class posts a particular NSNotification? (I have a set of classes, and I would like to enforce at compile-time (if possible) that the class posts a required NSNotification). Alternatively, if that is not possible, is there any workaround? 回答1: It's fundamentally impossible to predict at compile time what will happen at run time. The closest you can get is static analysis, but even that can't predict anything that happens outside of your own code, such as

Handle UILocalNotification in UIViewController using NSNotification after the app has been terminated

有些话、适合烂在心里 提交于 2019-12-13 00:04:52
问题 I'm working with UILocalNotification and I would like to notify one of my controller that the notification has been received even if the app has been terminated. In my appDelegate I implemented this function: -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { if ([application applicationState] == UIApplicationStateInactive) { [[NSNotificationCenter defaultCenter] postNotificationName:@"localNotificationReceived" object

Detecting Current Item in AVQueuePlayer and Knowing when it Changes?

岁酱吖の 提交于 2019-12-12 13:50:10
问题 I currently have an AVQueuePlayer playing a few .aif files in sequence. As it goes through each audio I want to perform an action related to that specific sound (for example changing an imageview's uiimage). My problem is setting the NSNotification correctly. I've set it to notify me when the queue finished with the last object, but I'm having trouble receiving an a notification for each current item. Here is what I have: //Setting Up My Queue List yellowVoice = [[AVPlayerItem alloc]

NSWorkspaceWillPowerOffNotification never called

前提是你 提交于 2019-12-12 11:30:13
问题 I am trying to run a program in a background process that will register every shutdown event in the system. Doing so by registering to NSWorkspaceWillPowerOffNotification as show below: #import <AppKit/AppKit.h> @interface ShutDownHandler : NSObject <NSApplicationDelegate> - (void)computerWillShutDownNotification:(NSNotification *)notification; @end int main(int argc, char* argv[]) { NSNotificationCenter *notCenter; notCenter = [[NSWorkspace sharedWorkspace] notificationCenter];

NSManagedObjectContextObjectsDidChangeNotification not always called instantly

a 夏天 提交于 2019-12-12 08:05:07
问题 I have an Mac Application using a NSPersistentDocument. I want to get notified when Objects are deleted to save this information using Core Data. So I'm listening for NSManagedObjectContextObjectsDidChangeNotification. Often it is called instantly when objects are deleted, but sometimes it is only called after the persistent document is saved with all deleted objects not being notified before. Because I want to let the user directly export all existing objects (and not the deleted anymore)

NSNotificationCenter calling two times

喜你入骨 提交于 2019-12-12 03:08:12
问题 Below is what I have. MainViewController.m - (IBAction)sideMenuAction:(id)sender { NSLog(@"login==sideMenuAction"); [[NSNotificationCenter defaultCenter] postNotificationName:@"ShowMySideMenuNotification" object:self]; } NotificationListener.m -(void)viewDidLoad { [[NSNotificationCenter defaultCenter] removeObserver:self name:@"ShowMySideMenuNotification" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(adjustShowMenu) name:@"ShowMySideMenuNotification"

UIKeyboardWillShowNotification is called three times

和自甴很熟 提交于 2019-12-11 11:22:02
问题 I need to move a UIView up as soon as the keyboard will become visible. But the problem I'm facing right now is that my UIKeyboardWillShowNotification is called three times when I'm using a custom Keyboard (e.g. SwiftKey) which results in a bad animation. Is there a way to handle only the last notification? I could easily dodge the first one because the height is 0, but the second one looks like a valid height and I don't find an answer on how to solve this. Here is what I've so far: override