nsnotification

unexpectedly found nil while unwrapping an Optional value keyboardWillShow

一曲冷凌霜 提交于 2019-12-18 07:10:20
问题 I have this code below which runs when the keyboardWillShowNotification is called: func keyboardWillShow(_ notification: Notification) { //ERROR IN THE LINE BELOW keyboard = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as AnyObject).cgRectValue animaton = (notification.userInfo?[UIKeyboardAnimationDurationUserInfoKey] as AnyObject).doubleValue UIView.animate(withDuration: 0.4, animations: { () -> Void in self.scrollView.frame.size.height = self.scrollViewHeight - self.keyboard

Best practice for applicationDidEnterBackground [closed]

不打扰是莪最后的温柔 提交于 2019-12-11 06:16:09
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . I am in the middle of writing an application that needs to reset certain parts of its state to a default state when the application calls applicationDidEnterBackground. What I would like to know is if it is a better practice to get a pointer to the view that needs to be reset

Available Notifications For NSDistributedNotificationCenter

感情迁移 提交于 2019-12-11 03:29:49
问题 I was looking for a list of Distributed Notifications that exists on mac like iTunes com.apple.iTunes.playerInfo but I couldn't find anything. I was wondering if other applications like Safari or QuickTime does have such notifications? And if they exists what are their notification names? Regards 回答1: By adding an observer and setting it's name to nil it will show all the notifications. [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(observerMethod:) name

Obj-C Cocoa Notification NSApplicationDidResignActiveNotification

狂风中的少年 提交于 2019-12-11 01:34:23
问题 I've a class called AppController.h/m I want to make something when the NSNotificationDidResignActiveNotification is sent. So i wrote this code in AppController.m: -(void) initialize(){ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidResignActive:) name:NSApplicationDidResignActiveNotification object:nil ]; } and then -(void) applicationDidResignActive (NSNotification*) note{ NSBeep(); } The problem is that the method isn't executed and i get this in

Forcing a language change notification iOS

筅森魡賤 提交于 2019-12-10 16:34:38
问题 my app is being localized and we are concerned with dialects. (ie. difference between spanish and spanish in peurto rico) I notice that just changing the region doesn't push a notification to the app that will trigger the localization.. only changing the language triggers this notification. In my app delegate i would like to check to see if the region has changed in my applicationDidBecomeActive method and if it has, i'd like to push the notification that iOS would have pushed if the language

How write unit test for receiving nsnotification asynchronous?

送分小仙女□ 提交于 2019-12-10 13:47:33
问题 I call rest web servic with completion handler and if succeed I send NSNotification. The problem is how to write unit test to assert that the notification is sent in case of success. Any help will be appreciated. 回答1: You can add an expectation for the notification: expectationForNotification("BlaBlaNotification", object: nil) { (notification) -> Bool in // call the method that fetches the data sut.fetchData() waitForExpectationsWithTimeout(5, handler: nil) But personally I would split this

AVPlayerItemDidPlayToEndTimeNotification only works if forced

♀尐吖头ヾ 提交于 2019-12-10 11:56:20
问题 I been searching everywhere and I still can't find a solution to this problem. I have a AVQueuePlayer for a radio app that I am making. It has about 20 AVPlayerItems queued at a time. I added the AVPlayerItemDidPlayToEndTimeNotification observer to each one of those items. The notification gets fired and executes the code to remove key observers for metadata and status so it doesn't crash and advances to next item in the queue. However it doesn't want to play. There is no error, the status is

Overhead of NSNotifications

孤街浪徒 提交于 2019-12-10 11:39:47
问题 I recently started using NSNotification s: [[NSNotificationCenter defaultCenter] postNotificationName: selector: object:]; .... I find it to be an awesome concept for communicating between view controllers. It almost seems a little too easy to use NSNotification s for all the communications in the app. In the event that I use NSNotification s for most of the work in my app, what do you think would be the overhead for too many of them? 回答1: I seem to recall reading that NSNotification is

Is subclassing NSNotification the right route if I want to add typed properties?

北城以北 提交于 2019-12-10 01:54:59
问题 I am trying to subclass NSNotification . Apple's docs for NSNotification state the following: NSNotification is a class cluster with no instance variables. As such, you must subclass NSNotification and override the primitive methods name , object , and userInfo . You can choose any designated initializer you like, but be sure that your initializer does not call NSNotification ’s implementation of init (via [super init] ). NSNotification is not meant to be instantiated directly, and its init

When responding to NSNotifications, what is the best practice for updating UIViews

别来无恙 提交于 2019-12-08 00:44:30
问题 Since the NSNotification invokes its selector on a thread other than the main thread, I notice that any changes that you make to UIViews or other interface elements in response to that notification are often slow to take effect. This is most acute if the main thread is busy (as mine often is!). I can solve the problem by calling "performSelectorOnMainThread:". Is this really the best practice? - (void) gotMovieSaveFinishNotication: (NSNotification *) not { NSURL *exportMovieURL = (NSURL *)