Open a modal window with automatic close after time interval

   {
        NSDate *endDate = [NSDate dateWithTimeIntervalSinceNow:15];
        NSModalSession session = [NSApp beginModalSessionForWindow:window];
        [window orderFrontRegardless];
        for (;;) {
            if ([NSApp runModalSession:session] != NSRunContinuesResponse ||
                ![window isVisible] ||
                ([(NSDate *)[NSDate dateWithTimeIntervalSinceNow:0] compare:(NSDate *)endDate] ==         NSOrderedDescending)) {
                break;
            }
        }
        [NSApp endModalSession:session];
        [window orderOut:nil];
   }

Blogged with Flock

Tags: , ,

Advertisements