nsnotificationcenter

Why is my NSNotification its observer called multiple times?

旧街凉风 提交于 2019-11-28 22:52:16
Within an App I make use of several viewcontrollers. On one viewcontroller an observer is initialized as follows: [[NSNotificationCenter defaultCenter] removeObserver:self name:@"MyNotification" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMethod:) name:@"MyNotification" object:nil]; Even when removing the NSNotification before initializing the number of executions of myMethod: is being summed up by the amount of repeated views on the respective viewcontroller. Why does this happen and how can I avoid myMethod: being called more then once. Note: I

How to write Keyboard notifications in Swift 3

本秂侑毒 提交于 2019-11-28 22:38:15
问题 I'm trying to update this code to swift 3: NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name: UIKeyboardWillShowNotification, object: nil) NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name: UIKeyboardWillHideNotification, object: nil)` So far, I've just tried the auto corrections given by the compiler. This results in code like this: let notificationCenter = NotificationCenter.default()

pausing spritekit game on app launch / exit .. iOS8

末鹿安然 提交于 2019-11-28 21:39:36
I've read everything I could find on this topic and still cant figure out my issue. I have tried pausing my game in every area of appdelegate func applicationWillResignActive(application: UIApplication!) { NSNotificationCenter.defaultCenter().postNotificationName("pauseGameScene", object: self) } func applicationDidEnterBackground(application: UIApplication!) { NSNotificationCenter.defaultCenter().postNotificationName("pauseGameScene", object: self) } func applicationWillEnterForeground(application: UIApplication!) { NSNotificationCenter.defaultCenter().postNotificationName("pauseGameScene",

is it ok to use of a notification to communication back to the main thread of an IOS app? (cf performSelectorOnMainThread)

一笑奈何 提交于 2019-11-28 19:41:12
Is it ok to use of a notification to communication back to the main thread of an IOS app? (cf performSelectorOnMainThread). That is, there are are there any gottcha's for this purpose? Background want to call back to main UI thread from a background thread (e.g. performSelectorInBackground) could use performSelectorOnMainThread to communicate back, but wondering if it is OK to use a notification? For example [[NSNotificationCenter defaultCenter] postNotificationName:@"ModelChanged" object:self]; Actually there is a gottcha; you'll crash randomly! That has been my experience. This has to do

Observing Changes to a mutable array using KVO vs. NSNotificationCenter

青春壹個敷衍的年華 提交于 2019-11-28 18:48:43
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 being called and I discovered that Arrays are not KVO compliant :-( One option is to manually trigger

How to pass a NSDictionary with postNotificationName:object:

╄→尐↘猪︶ㄣ 提交于 2019-11-28 17:29:26
问题 I am trying to pass an NSDictionary form a UIView to a UIViewController using NSNotificationCenter. The dictionary works fine at the time the notification is posted, but in the receiving method I am unable to access any of the objects in the dictionary. Here is how I am creating the dictionary and posting the notification... itemDetails = [[NSDictionary alloc] initWithObjectsAndKeys:@"Topic 1", @"HelpTopic", nil]; [[NSNotificationCenter defaultCenter] postNotificationName:@"HotSpotTouched"

NSOperation and NSNotificationCenter on the main thread

送分小仙女□ 提交于 2019-11-28 16:44:44
I have an NSOperation. When it is finished I fire a NSNotificationCenter to let the program know that the NSoperation is finished and to update the gui. To my understanding listeners to the NSNotification will not run on the main thread because the NSOperation is not on the main thread. How can I make it so that the listeners run on the main thread when I fire my event? [[NSNotificationCenter defaultCenter] postNotificationName:@"myEventName" object:self]; You can use performSelectorOnMainThread:withObject:waitUntilDone: with using a helper method, in a similar fashion to the following example

how to use the object property of NSNotificationcenter

不想你离开。 提交于 2019-11-28 15:06:23
问题 Could somebody please show me how to use the object property on NSNotifcationCenter. I want to be able to use it to pass an integer value to my selector method. This is how I have set up the notification listener in my UI View. Seeing as I want an integer value to be passed I'm not sure what to replace nil with. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveEvent:) name:@"myevent" object:nil]; - (void)receiveEvent:(NSNotification *)notification { // handle

can my app knows that I received a sms on my iphone using Notification Center

倖福魔咒の 提交于 2019-11-28 14:39:50
I am, creating a app in which i need to show message to user that you received sms , is it possible using NSNotificationCenter. Please help? It's not possible, as far as I know. iOS treats a new SMS very similarly to a push notification sent to the system, and your code doesn't get notified of push notifications that are not sent to your app. To reiterate, iOS does not notify your app when an SMS (text message) has been received by your phone. 来源: https://stackoverflow.com/questions/9100242/can-my-app-knows-that-i-received-a-sms-on-my-iphone-using-notification-center

Android equivalent to NSNotificationCenter

一笑奈何 提交于 2019-11-28 13:27:07
问题 In the process of porting an iPhone application over to android, I am looking for the best way to communicate within the app. Intents seem to be the way to go, is this the best (only) option? NSUserDefaults seems much lighter weight than Intents do in both performance and coding. I should also add I have an application subclass for state, but I need to make another activity aware of an event. 回答1: You could try this: http://developer.android.com/reference/java/util/Observer.html 回答2: The best