Just before closing your document, you could issue a notification for which your application delegate could register as an observer.
When your application delegate receives the notification (which could convey the URL you need to open), a method on your application delegate could be called to open the URL for you.
You do this through the use of the instance of NSNotificationCenter
that comes with every Cocoa application (more accurately, it's a singleton). Your document would issue the notification something like this:
NSDictionary *myUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:@"http://www.apple.com", @"MyURL", nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"MyNotificationName" object:self userInfo:myUserInfo];
In your application delegate, probably in your -awakeFromNib
method, you'd use something like this:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myURLOpenerMethod:) name:@"MyNotificationName" object:nil];
And somewhere in your application delegate, you could define that URL opener like this:
- (void)myURLOpenerMethod:(NSNotification *)notification
{
NSString *urlString = [[notification userInfo] objectForKey:@"MyURL"];
// use 'urlString' to open your URL here
}
You do not want to try using delays to get what you want. I promise you: That way madness lies.