Prevent iCloud window from opening on OSX 10.8 app launch

前端 未结 2 735
南笙
南笙 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 03:54

    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.

    0 讨论(0)
  • 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];
        }
    }
    
    0 讨论(0)
提交回复
热议问题