I've just added iCloud support to an app that I am working on. Its working great, except that when I open the application without a document in focus the iCloud open file dialog appears and I don't want it to!
In my app delegate I have:
- (BOOL) applicationShouldOpenUntitledFile:(NSApplication *)sender
{
[mainWindowController.window makeKeyAndOrderFront:self];
return NO;
}
Which I use to show my own custom window. However now, both the iCloud open file dialog and my own dialog are displayed. Any ideas on how I can get rid of the iCloud dialog?
https://developer.apple.com/library/prerelease/content/releasenotes/AppKit/RN-AppKitOlderNotes/index.html
So if you can give up using the features listed in this release note,
return NO
at+[NSDocument usesUbiquitousStorage]
. I confirmed you can still open/save your file into iCloud storage from the normal dialog.Putting below codes in your App Delegate lets you bypass that iCloud pop up New Document screen. Tested for High Sierra.
I ran into a similar problem -- it turned out that in my case, I had to remove the
NSDocumentClass
key and value from my Info.plist in theCFBundleDocumentTypes
array. Only then would theapplicationShouldOpenUntitledFile:
method get called and thus allow me to prevent the iCloud/Document window from opening.This part is correct. I've just tested it.
Just make sure your that this class is really your app delegate.
MainMenu.xib
, drag a new object to the side and set it's custom class to the app delegate classIf that still doesn't help, try logging something in
applicationShouldOpenUntitledFile:
.Also, I recommend not to set
[mainWindowController.window makeKeyAndOrderFront:self];
in this method. You should rather use the app delegate methodapplicationDidFinishLaunching:
method.I thought I would share my solution to this issue as I see others still looking for an answer. Its not a great solution but it does the trick.
Add the following to your app delegate:
And the reasoning -- By setting a breakpoint in
openDocument
I've found that its called beforeapplicationDidFinishLaunching
,applicationShouldOpenUntitledFile
orapplicationShouldHandleReopen:hasVisibleWindows:
get called, meaning adding those methods is useless. Again, it's not great code but it works and does the trick. (None of the other solutions have worked for me).My observation and fix: [applicationShouldOpenUntitledFile:] won't be executed except you remove Key
NSDocumentClass
from *-info.plist. But this is harmful if your app is document based application, it won't open the document type you linked.My fix is open my customised window directly in
-(void)applicationWillFinishLaunching:(NSNotification *)notification
method (Application delegate)