nsnotificationcenter

Broadcast data to multiple widgets in Flutter

别等时光非礼了梦想. 提交于 2019-11-30 15:40:52
Is there a way to broadcast data from one widget to other widgets? Similar to a BroadcastReceiver on Android or NSNotificationCenter on iOS. Specifically, I'm trying to detect when a Navigator pops or pushes a new view. I added navigatorObservers to MaterialApp. And when a widget comes back to the foreground, I want to be able to notify it by broadcasting changes from didPush and didPop with the actual route that's in the current foreground Navigator.push returns a Future that will complete when Navigator.pop is called (and this can optionally be used to pass data back to the widget that

Use IBAction from UIButton inside custom cell in main view controller

随声附和 提交于 2019-11-30 13:24:22
问题 I have created a custom cell with its own .m, .h and .xib file. In the cell, I have a UIButton that I added to the xib in IB. I can receive the IBAction from the UIButton in this custom cell's .m, but really, I'd like to be forwarding that button press to the main view .m that is hosting the table (and so custom cell) and use an action there. I've spent the last 4 hours attempting various ways of doing this - should I be using NSNotificationCenter? (I've tried Notifications lots but can't get

UIApplicationBackgroundRefreshStatusDidChangeNotification usage without corresponding delegate method

非 Y 不嫁゛ 提交于 2019-11-30 10:11:48
I feel that UIApplicationBackgroundRefreshStatusDidChangeNotification introduced in iOS 7 is of little use without supporting UIApplication delegate method. Because, the app is not notified when user has switch ON the background refresh state for my app. This is my notification handler... - (void)applicationDidChangeBackgroundRefreshStatus:(NSNotification *)notification { NSLog(@"applicationDidChangeBackgroundRefreshStatus with notification info = %@ and refresh status = %d", notification, UIApplication.sharedApplication.backgroundRefreshStatus); if (UIApplication.sharedApplication

NSNotificationCenter and safe multithreading

孤街浪徒 提交于 2019-11-30 09:16:16
Given that objects may be deallocated even while a method invocation is in progress ( link ) *, is it safe for an object to register for and receive notifications that will be delivered on a thread that is different from the one on which it expects to be deallocated? For reference, the documentation states that In a multithreaded application, notifications are always delivered in the thread in which the notification was posted, which may not be the same thread in which an observer registered itself. Also important is the fact that NSNotificationCenter does not keep a strong reference to

NSUserNotificationCenter dismiss notification

一世执手 提交于 2019-11-30 08:09:09
I'm trying to use the new Mountain Lion NSUserNotificationCenter for my application (which isn't too hard actually). Posting notifications works like a charm via NSUserNotification *userNotification = [[NSUserNotification alloc] init]; userNotification.title = @"Some title"; userNotification.informativeText = @"Some text"; [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:userNotification]; However, i'd like to dismiss all notifications that are on the screen once the app gains focus. E.g. like the new Messages app does it. When new messages are received in the

CNContactStoreDidChangeNotification is fired multiple times

為{幸葍}努か 提交于 2019-11-30 07:57:51
I am able to observe the CNContactStoreDidChangeNotification when the contact database is changed while the app is in background state. I am pretty sure that only one observer was added to NSNotificationCenter . The problem is NSNotificationCenter posts MULTIPLE times (2, 3, 5, and even more times) even if I only add one new contact. Where is the problem? Make certain you aren't adding the observer multiple times. This can happen without you realizing it if (for example) you call -addObserver from -viewDidLoad or -viewDidAppear in your view controller (as these might get called more than once

Use IBAction from UIButton inside custom cell in main view controller

对着背影说爱祢 提交于 2019-11-30 07:26:21
I have created a custom cell with its own .m, .h and .xib file. In the cell, I have a UIButton that I added to the xib in IB. I can receive the IBAction from the UIButton in this custom cell's .m, but really, I'd like to be forwarding that button press to the main view .m that is hosting the table (and so custom cell) and use an action there. I've spent the last 4 hours attempting various ways of doing this - should I be using NSNotificationCenter? (I've tried Notifications lots but can't get it to work and not sure if i should be persevering) Moonkid You need to use delegate in .h file of

NSUserDefaultsDidChangeNotification: What's the name Of the Key, that Changed?

泄露秘密 提交于 2019-11-30 07:16:36
This code will call the method "defaultsChanged", when some value in UserDefaults changed NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; [center addObserver:self selector:@selector(defaultsChanged:) name:NSUserDefaultsDidChangeNotification object:nil]; This Code will give me the VALUE that changed - (void)defaultsChanged:(NSNotification *)notification { // Get the user defaults NSUserDefaults *defaults = (NSUserDefaults *)[notification object]; // Do something with it NSLog(@"%@", [defaults objectForKey:@"nameOfThingIAmInterestedIn"]); } but how can I get the NAME of the

Observing Changes to a mutable array using KVO vs. NSNotificationCenter

不打扰是莪最后的温柔 提交于 2019-11-30 06:26:24
问题 In my model I have an array of objects called events. I would like my controller to be notified whenever a new object is added to events. I thought that a good way to do this would be use the KVO pattern to get notified when the events changes (from a new object being added) // AppDelegate // events is a NSMutableArray @property/@synthesize etc... [appDelagate addObserver:self forKeyPath:@"events" options:NSKeyValueObservingOptionNew context:NULL]; But the observeValueForKeyPath method wasn't

What is parameter `object` in NSNotification addObserver:?

百般思念 提交于 2019-11-30 06:23:55
One of my class named Message.m is posting a notification with an object sentObject as below NSDictionary *sentObject = [NSDictionary dictionaryWithObjectsAndKeys:draftData.arr,@"data", nil]; //Post notification to inform a receiver to reload data [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadDuringSave" object:self userInfo:sentObject]; DraftData.m will be be the receiver to catch the notification as follow [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dataReloaded:) name:@"reloadDuringSave" object:nil]; For posting notification, userInfo can