Prevent iCloud window from opening on OSX 10.8 app launch

前端 未结 2 724
南笙
南笙 2021-02-20 03:05

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:

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-20 04:02

    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];
        }
    }
    

提交回复
热议问题