nsnotificationcenter

NSMetaDataQuery never calls back with NSMetadataQueryDidFinishGatheringNotification

谁说胖子不能爱 提交于 2019-11-29 10:41:28
For an iCloud plugin I'm writing, I subscribe my iCloud manager class to these iCloud NSMetaDataQuery observers: // Add a predicate for finding the documents NSString* filePattern = [NSString stringWithFormat:@"*.%@", @"*"]; self.metadataQuery = [[NSMetadataQuery alloc] init]; // Before starting to query, it is required to set the search scope. arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]]; // It is also required to set a search predicate. [self.metadataQuery setPredicate:[NSPredicate predicateWithFormat:@"%K LIKE %@", NSMetadataItemFSNameKey, filePattern]]; // Listen for the

Posting NSNotification on the main thread

℡╲_俬逩灬. 提交于 2019-11-29 10:30:51
问题 I found the following code snippet which allows NSNotification to be posted on the main thread from any background thread. I would like to know if this is a safe and acceptable practice please? dispatch_async(dispatch_get_main_queue(),^{ [[NSNotificationCenter defaultCenter] postNotificationName:@"ImageRetrieved" object:nil userInfo:imageDict]; }); 回答1: Yes you can . Generally you want the NSNotifications to be sent on the main , especially if they trigger UI activities like dismissing a

How to invalidate an iOS push notification on iPad when handled on iPhone?

社会主义新天地 提交于 2019-11-29 08:20:00
Let's say a user has a messages app on their iPhone and iPad. They get a new message from the server, so a push notification is sent to both their devices. Now the user picks up their iPhone and reads the message waiting in notification center. How do I now remove the message from notification center (and the app badge number) on their iPad, since it's already been read? When the user reads the message on the iPhone (presumably after tapping on the notification or the launch icon of the app), you can execute some API call on your server to notify it that the user read the message. If you

Is there any way to “wait here…” in code - just like an empty loop?

雨燕双飞 提交于 2019-11-29 07:46:57
Consider this code: [self otherStuff]; // "wait here..." until something finishes while(!self.someFlag){} [self moreStuff]; Note that this all happens ON THE SAME THREAD - we do not want to go to another thread. otherStuff could do things like connect to the cloud, get input from the user, etc. so it would take a lot of time and could follow many possible paths. otherStuff would set self.someFlag to true, when otherStuff is finally finished. This works perfectly and there's no problem with it at all -- except that it's lame to burn up the processor like that with the empty loop!! Quite simply,

Detect Change in UILabel Text

[亡魂溺海] 提交于 2019-11-29 06:38:41
Is it possible to set a Notification for when a UILabel's text property is changed? I tried the one used for UITextFields when I couldn't find one for a UILabel, but it didn't work. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(posttosocial) name:UITextFieldTextDidChangeNotification object:nowplaying]; You can use key-value observing (KVO): [label addObserver:self forKeyPath:@"text" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:NULL]; - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change

What is parameter `object` in NSNotification addObserver:?

爷,独闯天下 提交于 2019-11-29 05:11:09
问题 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:

NSNotificationCenter vs delegation - which is faster?

自闭症网瘾萝莉.ら 提交于 2019-11-29 03:47:28
I have read a lot about the pros and cons of each , and i know delegates are usually for one listener, and notifications are for many. The question is about performance. I have read this : NSNotificationCenter vs delegation( using protocols )? I am sending audio signals from mic, to another class by notification . i know that here i should use the delegate BUT my question is : does delegates will be faster ? because i can see i have some frame rate issue(decreased), and i would like to know if the cause could be the using of notification instead of delegate, or there is no relation ? Delegates

In ARC do we need to send removeObserver: explicitly?

随声附和 提交于 2019-11-29 03:23:21
Do we have to send removeObserver: explicitly for objects that have been added as observers to an NSNotificationCenter before? I am bit confused and unable to find the exact answer for this. Please provide me in detail, about this including why we need to removeObserver explicitly, and why don't compiler put it implicitly in class/application? rckoenes Yes, you need to call removeObserver: , if you don't the observed class could call all deallocated instance of the observer. From 10.11 observers are not required to un-register in their deallocation method. NSNotificationCenter and

Get Notification of NSStatusItem frame change?

人走茶凉 提交于 2019-11-29 02:37:55
In an app that uses a NSStatusItem with a custom view like this: ... how can you get notifications when: The status bar gets hidden because of a full screen app The status item moves position because another item is added/removed/resized? Both are necessary to move the custom view to the right position when the item changes places. There is a method -[NSStatusItem setView:] . When you set a custom view for your status item, this view is automatically inserted into a special status bar window. And you can access that window using a method -[NSView window] to observe its

NSNotification not being sent when postNotificationName: called

╄→尐↘猪︶ㄣ 提交于 2019-11-29 02:33:01
问题 I'm trying to get one instance of using NSNotificationCenter with addObserver and postNotificationName but I can't work out why it won't work. I have 2 lines to code to add the observer and send the message in 2 different classes [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(newEventLoaded:) name:@"Event" object:nil]; and [[NSNotificationCenter defaultCenter]postNotificationName:@"Event" object:self]; If I set the name to nil it works fine becuase it's just a