NWSWindow events sequence when NSWindow closes? - cocoa

Can Anyone give a list of NWSWindow events sequence when NSWindow closes. More specifically which is the last notification that a NSWindow that closes sends. Apple docs are very sparse on any sequence stuff.

The messages sent to a window when closing are – windowShouldClose: and – windowWillClose:. These are sent to the window's delegate and conform to the NSWindowDelegate protocol.
Also you can register to receive NSWindow's notifications such as NSWindowWillCloseNotification.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(windowWillCloseNotification:) name:NSWindowWillCloseNotification object:self.window];
- (void)windowWillCloseNotification:(NSNotification*)notification
{
// ... do something, save information...
NSWindow *window = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowWillCloseNotification object:window];
}

Related

Done button action of MPMoviePlayerViewController

I am using custom MPMoviePlayerViewController.
Like below,
#import <MediaPlayer/MediaPlayer.h>
#interface customVideoViewController : MPMoviePlayerViewController
{
}
#end
I am calling this customVideoViewController class from other class to RUN my video serially in landscape mode, video is running fine but I am not able to catch the action onClick of DONE button of MPMoviePlayerViewController.
Can any one guide me.
this is how I am calling to this view.
customVideoPlayerObj = [[customVideoViewController alloc]initWithContentURL:self.url];
[self presentViewController:customVideoPlayerObj animated:YES completion:nil];
[customVideoPlayerObj.moviePlayer play];
I need to catch the action for DONE button click of this, how to do this...?
here is the observer for the same
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(doneButtonClick:)
name:MPMoviePlayerWillExitFullscreenNotification
object:customVideoPlayerObj];
but control is not coming in doneButtonClick
MPMoviePlayerWillExitFullscreenNotification and MPMoviePlayerDidExitFullscreenNotification fired when the movie player exits fullscreen.
You can use MPMoviePlayerPlaybackDidFinishNotification .

How to detect when user opens the OS X Notification Center?

How do I detect when a user opens the OS X Mountain Lion Notification Center?
Is there an NSNotification (ugh, very similar term for a different thing) which I can observe?
I don't know of any officially documented solution or notification (let me know!), but this appeared to work (at least on OS X 10.10) when I tested it, so long as my application was in the foreground/had the frontmost window I believe.
Add your object as an observer:
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:#selector(notificationCenterOpened:) name:#"com.apple.HIToolbox.beginMenuTrackingNotification" object:nil];
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:#selector(notificationCenterClosed:) name:#"com.apple.HIToolbox.endMenuTrackingNotification" object:nil];
Add methods similar to the following to your object, making sure to check for the correct ToolboxMessageEventData number (4927), for example:
- (void)notificationCenterOpened:(NSNotification*)notification {
if ([notification.userInfo[#"ToolboxMessageEventData"] isEqual: #4927]) {
NSLog(#"Notification center opened");
}
}
- (void)notificationCenterClosed:(NSNotification*)notification {
if ([notification.userInfo[#"ToolboxMessageEventData"] isEqual: #4927]) {
NSLog(#"Notification center closed");
}
}
Let me know if that does or doesn't work for you.
Nevermind - upon restart/log-off + log back in, the ToolboxMessageEventData appears to change.

How to hide window of UIAgent process with cocoa

I have an UIAgent application with one window. I want to hide/show it from another application.How do I do it with cocoa? Seems like hide/unhide methods of NSRunningApplication doesn't affect UIAgent processes.
Thanks in advance
I solved it with NSDistributionNotifications. In the UIAgent application I add an observer to a #"QuitProcessNotification" (any other name):
[[NSDistributedNotificationCenter defaultCenter]
addObserver:self selector:#selector(quit:)
name:#"QuitProcessNotification"
object:#"com.MyCompany.MyApp"
suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately];
The callback looks like that:
- (void) quit:(NSNotification *) notification
{
[NSApp terminate:nil];
}
In the main application:
Sending notification:
[[NSDistributedNotificationCenter defaultCenter]
postNotificationName:#"QuitProcessNotification"
object:#"com.MyCompany.MyApp"
userInfo: nil /* no dictionary */
deliverImmediately: YES];
Be sure, that the object parameter is indeed your sender application's bundle identifier.

How do you reload a UIView?

I have a UINavigationController where the user can go back/fourth. When the user goes back, I want that UIView to reload. ( I am actually using an OHGridView ). On my ViewWillDisappear, I do something like this:
- (void)viewWillDisappear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] postNotificationName:#"ReloadOHGridView" object:self];
}
So when they go back, it will send a NSNotification to the OHGridView to refresh it's data. It get's called, but it get's an error Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DetailViewController reloadData]: unrecognized selector sent to instance 0x4b9e9f0
Here's how I set up my NSNotificationCenter (in my DetailViewController):
- (void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(ReloadGridNotification:) name:#"ReloadOHGridView" object:nil];
}
- (void)ReloadGridNotification:(NSNotification *)notification{
[database executeNonQuery:#"DELETE * FROM images"];
[items removeAllObjects];
[self reloadData];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
Now you would think it would update, but I get that error... Please help!
Coulton
Actually, I wouldn't think that it would update. reloadData isn't the name of a documented method of UIViewController, and you don't seem to have implemented one yourself. I'm not familiar with OHGridView, but I perhaps that's the object to which you want to send the reloadData message.
So you can change the observer that you set up from self to your instance of OHGridView, or you can implement a method in your view controller called reloadData that in turn sends the appropriate reload message to your OHGridView.

Application Will Enter Foreground Notification and memory

I'm adding my View Controller as a listener to UIApplicationWillEnterForegroundNotification in my viewDidLoad function (as recommended on previous questions here):
if(&UIApplicationWillEnterForegroundNotification != nil)
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(myFunc) name:UIApplicationWillEnterForegroundNotification object:nil];
}
}
The problem is that when debugging the application through Instruments it appears this line of code is extremely memory consuming. Any thoughts as to why and how to make it more effective?

Resources