【问题标题】:Prevent iCloud window from opening on OSX 10.8 app launch防止 iCloud 窗口在 OSX 10.8 应用启动时打开
【发布时间】:2013-03-22 05:58:20
【问题描述】:

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

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

更新:

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

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

【问题讨论】:

  • 否 -- 尽管症状相似,但建议的解决方案不起作用。在我的应用程序中 - (BOOL) applicationShouldOpenUntitledFile:(NSApplication *)sender 未被系统调用。
  • 我建议你回答你自己的问题。上面的更新 2 确实是一个答案。可以回答,此时等待1天后,可以接受。

标签: objective-c xcode cocoa osx-mountain-lion icloud


【解决方案1】:

来自iCloud enabled - Stop the open file displaying on application launch?applicationShouldOpenUntitledFile: 不起作用。经过大量实验,我发现如果我从 CFBundleDocumentTypes 数组中的 Info.plist 中删除 NSDocumentClass 键和值,则不再打开窗口。

【讨论】:

  • 当我删除了 NSPersistentDocument 子类的 makeWindowControllers 时仍然没有被调用。只有当我禁用 iCloud 时,它才会隐藏该窗口并调用 makeWindowControllers
【解决方案2】:

在您的 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];
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-01
    • 1970-01-01
    • 2012-11-29
    • 1970-01-01
    • 2019-10-06
    • 2022-06-11
    • 1970-01-01
    • 2019-02-17
    相关资源
    最近更新 更多