applicationShouldTerminate:
アプリケーションが終了するときに呼び出されます
-(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender:
解説
アプリケーションが終了するときに呼び出されます。
YESを返すと終了します。NOを返すと終了しません。
終了前になにか処理が必要な場合はNSTerminateLaterを返して、処理が終わってからNSAppに
replyToApplicationShouldTerminateを送信します。
NSTerminateLaterを送信した場合は2分以内に- (void)replyToApplicationShouldTerminate:(BOOL)shouldTerminate;を呼びます。
【NSApplicationTerminateReply】
NSTerminateCancel 終了しない
NSTerminateNow 今すぐ終了
NSTerminateLater 後で終了
返り値
( NSApplicationTerminateReply )
引数
( NSApplication * )sender
送信オブジェクト
フレームワーク
ApplicationKit
クラス
NSApplication
Instance Methods
使用可能
10.0
参照
例文
#import "Controller.h" @implementation Controller NSTimer *timer=nil; - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)theApplication { NSLog(@"applicationShouldTerminate"); NSDate *theDate = [NSDate dateWithTimeIntervalSinceNow:10]; //10秒後にタイマー起動 //userInfoに使う辞書を作成 NSDictionary *userInfoDictionary =[NSDictionary dictionaryWithObjectsAndKeys: @"value1",@"key1", @"value2",@"key2", @"value3",@"key3",nil]; //タイマー作成 timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target: self selector: @selector(timerControl:) userInfo: userInfoDictionary repeats:NO]; //起動時間セット [timer setFireDate:theDate]; [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSModalPanelRunLoopMode]; return NSTerminateLater; } //2分以内に -(void) timerControl:(NSTimer *)aTimer { NSLog(@"...%@",[[aTimer userInfo] objectForKey:@"key2"]); //NSLog([[timer fireDate] description]); [NSApp replyToApplicationShouldTerminate:YES]; } @end