Re: Is calling "-applicationOpenUntitledFile:" for app-open (but not app-reopen) out of fashion?
Re: Is calling "-applicationOpenUntitledFile:" for app-open (but not app-reopen) out of fashion?
- Subject: Re: Is calling "-applicationOpenUntitledFile:" for app-open (but not app-reopen) out of fashion?
- From: Ken Thomases <email@hidden>
- Date: Wed, 02 Mar 2016 12:24:37 -0600
On Mar 2, 2016, at 12:00 PM, Daryle Walker <email@hidden> wrote:
>
> The Apple-Event handling guide says that “-applicationOpenUntitledFile:” (at least on OS X 10.4) is supposed to be called on app-open. That didn’t happen when creating a default project on Xcode 7 using Swift and without documents nor Core Data. I made a “newDocument:” action handler and a common create window method.
>
> Once I added an “-applicationShouldOpenUntitledFile” method (and had it return TRUE), I did get a new window when I pressed the dock icon while the app had no windows, whether or not I switched to another app first. I figured out that was the reopen-app behavior, but the open-app behavior was still to do nothing. I can only guess that this is a deliberate change since 10.4; or that there’s some obscure setting to affect this (or a bug). This changed behavior is consistent when switching in and out of the app when using Command-Tab instead of the dock icon.
>
> I got around this by explicitly calling “applicationShouldOpenUntitledFile” and “applicationOpenUntitledFile” during my application-delegate's did-finish-launching handler (which, as I said, supposed to have been the default since 10.4).
>
> If this is a policy change, then the guide should be updated.
This should only happen on the second and subsequent launches of your app. The behavior should be as you were expecting for the first launch of your app in a new user account. Or if the user sets System Preferences > General > Close windows when quitting an app.
Switching to an app using Command-Tab has never opened a new untitled document/window.
The change is a consequence of User Interface Preservation (a.k.a. Resume, a.k.a. Window Restoration). The app is supposed to return to its last state when it is launched. To fully achieve that, you need to implement restoration in your app controller and/or window controllers.
<https://developer.apple.com/library/mac/documentation/General/Conceptual/MOSXAppProgrammingGuide/CoreAppDesign/CoreAppDesign.html#//apple_ref/doc/uid/TP40010543-CH3-SW26>
If you want your app to open a particular window that's not really an untitled document but, say, your main window, you should switch away from the UntitledFile methods and use, for example, -applicationDidFinishLaunching: or something like that to create your window.
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden