Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iCloud enabled - Stop the open file displaying on application launch?

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?

Default Window

like image 477
Kyle Avatar asked Dec 11 '12 17:12

Kyle


2 Answers

https://developer.apple.com/library/prerelease/content/releasenotes/AppKit/RN-AppKitOlderNotes/index.html

NSDocument Support for iCloud

In 10.8, NSDocument-based applications with a ubiquity-container-identifiers entitlement gain new functionality and UI to facilitate iCloud document management.

When iCloud is enabled and an application is first launched or re-activated and no windows are visible or being restored, instead of creating a new Untitled document, NSDocumentController will display a non-modal open panel showing the user's iCloud library.

...

Applications that do not wish to use these features for any or all of their NSDocument subclasses can override +[NSDocument usesUbiquitousStorage] and return NO. If all of the application's declared NSDocument subclasses return NO from this method, then NSDocumentController will never show the new non-modal open panel.

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.

like image 88
ioue Avatar answered Oct 20 '22 07:10

ioue


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];
    }
}
like image 36
coolcool1994 Avatar answered Oct 20 '22 09:10

coolcool1994