11

I have written an OSX app that uses iCloud document storage. Whenever I open it in Mountain Lion (not on Lion), an iCloud window opens that looks like the following:

enter image description here

Is there a way to prevent this from happening on launch?

Updates:

1) applicationShouldOpenUntitledFile: is not getting called (yes, I'm sure I'm listening in my delegate.
2) If I force quit the app, the next time it opens, I don't get the dialog. But, if I go through the normal Quit process, it does appear.

Update 2 (also added as an answer, to help people that may stumble across this question in the future): The applicationShouldOpenUntitledFile: from the duplicate question was not working. After lots of experimentation, I figured out that if I remove the NSDocumentClass key and value from my Info.plist in the CFBundleDocumentTypes array, the window is no longer opened. I've added that answer to the duplicate question as well.

jnpdx
  • 45,847
  • 6
  • 64
  • 94
  • [Does this related question have the answer for you?](http://stackoverflow.com/questions/13825228/icloud-enabled-stop-the-open-file-displaying-on-application-launch?rq=1) – Michael Dautermann Apr 01 '13 at 06:40
  • No -- although the symptoms are similar, the proposed solution doesn't work. In my app - (BOOL) applicationShouldOpenUntitledFile:(NSApplication *)sender is not being called by the system. – jnpdx Apr 01 '13 at 07:24
  • I suggest you answer your own question. Update 2 above is really an answer. You can answer it, and at this point, after the 1 day wait, you can accept it. – Warren P May 25 '13 at 23:35

2 Answers2

0

Putting below codes in your App Delegate lets you bypass that iCloud pop up New Document screen. Tested for High Sierra.

-(void)applicationDidFinishLaunching:(NSNotification *)notification
{
    // Schedule "Checking whether document exists." into next UI Loop.
    // Because document is not restored yet. 
    // So we don't know what do we have to create new one.
    // Opened document can be identified here. (double click document file)
    NSInvocationOperation* op = [[NSInvocationOperation alloc]initWithTarget:self selector:@selector(openNewDocumentIfNeeded) object:nil];
    [[NSOperationQueue mainQueue] addOperation: op];
}

-(void)openNewDocumentIfNeeded
{
    NSUInteger documentCount = [[[NSDocumentController sharedDocumentController] documents]count];

    // Open an untitled document what if there is no document. (restored, opened).       
    if(documentCount == 0){
        [[NSDocumentController sharedDocumentController]openUntitledDocumentAndDisplay:YES error: nil];
    }
}
coolcool1994
  • 3,704
  • 4
  • 39
  • 43
-1

The applicationShouldOpenUntitledFile: from iCloud enabled - Stop the open file displaying on application launch? was not working. After lots of experimentation, I figured out that if I remove the NSDocumentClass key and value from my Info.plist in the CFBundleDocumentTypes array, the window is no longer opened.

Community
  • 1
  • 1
jnpdx
  • 45,847
  • 6
  • 64
  • 94
  • when I removed that makeWindowControllers for NSPersistentDocument subclass still doesnt get called. Only when I disable iCloud, it hides that window and calls makeWindowControllers – coolcool1994 Jan 12 '18 at 00:31