nsnotificationcenter

Type 'NSNotification.Name' has no member 'keyboardDidShowNotification'

耗尽温柔 提交于 2019-11-27 08:54:53
I'm getting this error with Swift 4.2 Type 'NSNotification.Name' has no member 'keyboardDidShowNotification' Here is my code: NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardDidShow(notification:)), name: NSNotification.Name.keyboardDidShowNotification, object: nil) Following one was working fine with Swift 4 but not with Swift 4.2 NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardDidShow(notification:)), name: NSNotification.Name.UIKeyboardDidShow, object: nil) Apple document Ref: NSNotification.Name.keyboardDidShowNotification I

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

怎甘沉沦 提交于 2019-11-27 08:50:06
问题 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? 回答1: 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

NSNotification VS KVO

北慕城南 提交于 2019-11-27 03:38:15
问题 I feel that i don't fully understand difference between KVO and NSNotification... They seem to be so similar... Could you make some example showing when is best to use one method and when the other ? I don't speak about Bind and IB, but i mean add Observer programmatically in my code with NSNotificationCenter or KVO [self.preferenceController addObserver:self forKeyPath:@"color" options:NSKeyValueObservingOptionOld context:@"Color-change" ]; 回答1: KVO only works on values, NSNotification can

iOS 11 - Keyboard Height is returning 0 in keyboard notification

雨燕双飞 提交于 2019-11-27 03:25:14
I have been using Keyboard notifications without any problem and getting exact height of Keyboard. - (void)keyboardDidShow:(NSNotification *) notification{ CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; NSLog(@"%f",keyboardSize.height);} but with iOS 11 the size of keyboard is 0 when the notification is called. What is the problem occurring in this scenario? I am using xcode 9 Beta 5 Use this: CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; For Swift, you can use:

NSNotificationCenter Swift 3.0 on keyboard show and hide

懵懂的女人 提交于 2019-11-27 02:45:10
问题 I am trying to run a function when the keyboard shows and disappears and have the following code: let notificationCenter = NotificationCenter.default notificationCenter.addObserver(self, selector: #selector(ViewController.keyBoardUp(Notification :)), name: NSNotification.Name.UIKeyboardWillShow, object: nil) And the function keyBoardUp below: func keyBoardUp( Notification: NSNotification){ print("HELLO") } However the function doesn't print to the console when the keyboard shows. Help would

How to pass object with NSNotificationCenter

被刻印的时光 ゝ 提交于 2019-11-26 23:36:24
I am trying to pass an object from my app delegate to a notification receiver in another class. I want to pass integer messageTotal . Right now I have: In Receiver: - (void) receiveTestNotification:(NSNotification *) notification { if ([[notification name] isEqualToString:@"TestNotification"]) NSLog (@"Successfully received the test notification!"); } - (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissSheet) name:UIApplicationWillResignActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self

Swift 3 NSNotificationCenter Keyboardwillshow/hide

ⅰ亾dé卋堺 提交于 2019-11-26 23:29:31
问题 I have a piece of code that worked in Swift 2 and I tried using Xcode to update the code to the newest version and I fixed everything except two issues. I have this code : let loginvc: LoginVC = self.storyboard?.instantiateViewController(withIdentifier: "LoginVC") as! LoginVC NotificationCenter.defaultCenter().addObserver(self, selector: #selector(LoginViewController.keyboardWillShow(_:)), name: UIKeyboardWillShowNotification, object: nil) NotificationCenter.defaultCenter().addObserver(self,

How to create a class to send and receive events through NSNotificationCenter in Objective-C?

谁都会走 提交于 2019-11-26 23:05:47
问题 I need to create two classes and both should be able to send and receive the events through the NSNotificationCenter methods.ie Both should have the sendEvent and receiveEvent methods: @implementation Class A -(void)sendEvent { addObserver:--- name:---- object:--- } -(void)ReceiveEvent { postNotificationName: --- object:--- } @end Same as such another class say ClassB should also be able to send and receive the events. How can it be done? 回答1: Ideally an object would start observing

iOS NSNotificationCenter to check whether the app came from background to foreground

倾然丶 夕夏残阳落幕 提交于 2019-11-26 22:03:13
问题 I have a situation in which i have to intialize an object everytime when it comes from background to foreground and that should be using the NSNotificationCenter not with appdelegate because iam building a static library so there wont be appdelegate with that so please help me in the same. 回答1: Have you tried UIApplicationWillEnterForegroundNotification ? The app also posts a UIApplicationWillEnterForegroundNotification notification shortly before calling applicationWillEnterForeground: to

OSX: Detect system-wide keyDown events?

十年热恋 提交于 2019-11-26 21:26:57
I'm working on an typing-tutor application for Mac OSX that needs to have keystrokes forwarded to it, even when the application is not in focus. Is there a way to have the system forward keystrokes to the app, possibly through NSDistributedNotificationCenter? I've googled myself silly, and haven't been able to find an answer... EDIT: Sample code below . Thanks @NSGod for pointing me in the right direction -- I ended up adding a global events monitor using the method addGlobalMonitorForEventsMatchingMask:handler: , which works beautifully. For completeness, my implementation looks like this: //