11

我编写了一个使用 iCloud 文档存储的 OSX 应用程序。每当我在 Mountain Lion(而不是 Lion)中打开它时,会打开一个 iCloud 窗口,如下所示:

在此处输入图像描述

有没有办法防止这种情况在发布时发生?

更新:

1)applicationShouldOpenUntitledFile:没有被调用(是的,我确定我在听我的委托
。2)如果我强制退出应用程序,下次打开时,我不会得到对话框。但是,如果我通过正常的退出过程,它确实会出现。

更新 2(也作为答案添加,以帮助将来可能偶然发现此问题的人):来自重复问题 的applicationShouldOpenUntitledFile:问题不起作用。经过大量实验,我发现如果我NSDocumentClass从数组中的 Info.plist 中删除键和值CFBundleDocumentTypes,则不再打开窗口。我也将该答案添加到了重复的问题中。

4

2 回答 2

0

在您的 App Delegate 中放置以下代码可以让您绕过 iCloud 弹出的新文档屏幕。经过高山脉测试。

-(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];
    }
}
于 2018-01-19T22:03:06.780 回答
-1

从iCloud 启用 - 停止在应用程序启动applicationShouldOpenUntitledFile:显示打开的文件?没有工作。经过大量实验,我发现如果我从数组中删除键NSDocumentClass和值,窗口将不再打开。Info.plistCFBundleDocumentTypes

于 2013-05-26T04:28:08.793 回答