Prevents the opening of the iCloud dialog box on startup in OS X

When you open an iCloud-based document-based application on a Mac without any documents currently open, a dialog box opens with an open file. How do you prevent an open file dialog from appearing at startup? I have a welcome screen that I prefer to display.

+8
objective-c macos
source share
1 answer

To test your claim, I created a new document-based application project in Xcode and launched it. I do not open a dialog box with an open file! However, I get a blank new document. Did you mean that? I could not find a documented way to prevent the opening of this open blank document. I managed to suppress this behavior with the following hack using the initializer of your Document class:

- (instancetype)init { self = [super init]; if (self) { // Add your subclass-specific initialization here. } NSLog(@"Document init"); if (alreadysuppressed) return self; alreadysuppressed = 1; return nil; } 

As you can see, a variable (called "alreadysuppressed" here) is used to remember whether the suppression has already been completed, so this will be done once to run the application. I know this is a hack, but it works for a general document-based application. If you really get a file open dialog instead of the above behavior, I suggest adding a similar hack to the application delegation class:

 - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender { NSLog(@"applicationShouldOpenUntitledFile: %d", alreadysuppressed); if (! alreadysuppressed) { alreadysuppressed = 1; return NO; } return YES; } 

Although I could not test this scenario, since I do not open the file open dialog in the application based on a common document.

+1
source share

All Articles