nsnotificationcenter

iOS NSNotificationCenter Observer not being removed

浪子不回头ぞ 提交于 2020-02-28 07:15:16
问题 I have the following code within AppDelegate. The purpose being to create a couple of observers, and then call some code. Once that code completes it then posts a notification, and the observer should then remove both observers and call the completion handler. My issue is that it appears that the observers are not being removed as I expected. The notification is posted, and the NSLog entry is written to console, so I know that the observer is working. However, on the second time of calling,

iOS NSNotificationCenter Observer not being removed

痞子三分冷 提交于 2020-02-28 07:14:12
问题 I have the following code within AppDelegate. The purpose being to create a couple of observers, and then call some code. Once that code completes it then posts a notification, and the observer should then remove both observers and call the completion handler. My issue is that it appears that the observers are not being removed as I expected. The notification is posted, and the NSLog entry is written to console, so I know that the observer is working. However, on the second time of calling,

uidevicebatterystatedidchangenotification not working sometimes

和自甴很熟 提交于 2020-02-25 04:41:55
问题 I am trying to check if device's charging port is working fine. There are two scenarios - a. when the charging cable is already plugged in. b. when the charging cable is plugged in after sometime. For case a, on viewDidLoad() I checked for enable batteryStateMonitoring and checked the current state of the battery. - It always works. For case b, I tried using NSNotification s UIDeviceBatteryStateDidChangeNotification override func viewDidLoad() { UIDevice.current.isBatteryMonitoringEnabled =

uidevicebatterystatedidchangenotification not working sometimes

痴心易碎 提交于 2020-02-25 04:39:07
问题 I am trying to check if device's charging port is working fine. There are two scenarios - a. when the charging cable is already plugged in. b. when the charging cable is plugged in after sometime. For case a, on viewDidLoad() I checked for enable batteryStateMonitoring and checked the current state of the battery. - It always works. For case b, I tried using NSNotification s UIDeviceBatteryStateDidChangeNotification override func viewDidLoad() { UIDevice.current.isBatteryMonitoringEnabled =

App crashing: Exception - unrecognised selector sent to instance

倾然丶 夕夏残阳落幕 提交于 2020-01-25 07:58:10
问题 I've got a UITableviewController with following logic to slide up / down the entire view once the keyboard toggles like so: class ChatDetailViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { // variables... override func viewDidLoad() { super.viewDidLoad() // do stuff... NotificationCenter.default.addObserver(self, selector: Selector(("keyboardWillShow:")), name: UIResponder.keyboardWillShowNotification, object: nil) NotificationCenter.default.addObserver(self,

Avoid Retain Cycles, NSNotificationCenter?

廉价感情. 提交于 2020-01-24 04:29:06
问题 Will this category method allow me to avoid additional retains on NSNotificationCenter observers? #import "NSNotificationCenter+Util.h" @implementation NSNotificationCenter (Util) - (void)addWeakObserver:(nonnull NSObject*)observer selector:(nonnull SEL)aSelector name:(nullable NSString *)aName object:(nullable id)anObject { __weak NSObject *weakObserver = observer; [self addObserver:weakObserver selector:aSelector name:aName object:anObject]; } @end The goal is to have the object die without

How do I debug this error: CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER?

自古美人都是妖i 提交于 2020-01-22 09:32:09
问题 I am getting an error in my app that I have no idea of how to figure out, has anyone seen this before: # Binary Image Name Address Symbol 0 RepZio 0x002bd302 testflight_backtrace 1 RepZio 0x002bc996 TFSignalHandler 2 libsystem_platform.dylib 0x39ce0062 _sigtramp 3 CoreFoundation 0x2edde118 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ 4 CoreFoundation 0x2ed52256 _CFXNotificationPost 5 Foundation 0x2f737c2c -[NSNotificationCenter postNotificationName:object:userInfo:] 6 Foundation

Use NSNotificationCenter selector for one observer in multiple view controllers

隐身守侯 提交于 2020-01-22 02:08:51
问题 Can I use the selector getUpdate: in multiple view controllers? I'm registering my LevelViewController as an observer for both GameViewController and WinViewController . The latter 2 view controllers both have a back button (which, when pressed, pops you back to LevelVC ), and the idea with the notification is to tell LevelVC whether or not to update the collection view cells (via the viewWillAppear: method) when the back button is pressed. In viewWillAppear: , I wouldn't want to call two

Help With NSNotifcation and Asynchronous Downloading

我们两清 提交于 2020-01-17 04:14:12
问题 I am sending a notification from one view to another view. My problem is that the notification in the view that I am calling in my cellForRowAtIndexPath method is only getting sent when the tableview is scrolling. How can I stop this and make it send the notification once the images have downloaded? Here is my code: https://gist.github.com/756302 Thanks MKDev 回答1: as far as I understand your code, the message will trigger the reload of the whole table. That should lead to a refresh of the

can't receive a notification after posting inside connectionDidFinishLoading:, NSURLConnection delegate method

白昼怎懂夜的黑 提交于 2020-01-16 11:59:10
问题 I can't receive a notification with this: a class for doing NSURLConnection async stuff - (void)connectionDidFinishLoading:(NSURLConnection *)connection { NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:_receivedData, @"receivedData", nil]; [[NSNotificationCenter defaultCenter] postNotificationName:kWebServiceURLTemperaturaMaximaKMLNotitificationName object:self userInfo:userInfo]; } another class observing the notification: [[NSNotificationCenter defaultCenter]