Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

How to prevent automatic State Restoration if the app was launched to open specific documents?

$
0
0

I have implemented State Restoration in my AppKit (Cocoa) app. That works.

However: If the user opens the app by double clicking a document file saved by the app, then I want the app not to restore the previous windows but only open the document that was opened in Finder.

The problem is that the state restoration appears to happen before the handlers for opening document files are invoked, so even if I had a way to suppress the state restoration, I have no knowledge of the pending openURL calls at that point, yet.

I understand that I could check the launch arguments, but that seems to be a rather dirty way. I'd think that I should be able to query the stored file paths/URLs from the app object somehow, but I can't find anything.

Or can I change the order of restoring documents vs. opening documents? I've so far found out that both happens deep inside [NSDocument restoreDocumentWindowWithIdentifier:state:completionHandler:], inside the completionHandler function. I could not find an overridable function below that where I'd have more control over this, though.


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>