启用了iCloud-停止在应用程序启动时显示打开的文件吗? [英] iCloud enabled - Stop the open file displaying on application launch?

查看:217
本文介绍了启用了iCloud-停止在应用程序启动时显示打开的文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将iCloud支持添加到了我正在开发的应用程序中.它的工作非常好,除了当我在没有文档的情况下打开应用程序时,会出现"iCloud打开文件"对话框,而我却不希望这样做!

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

我用来显示自己的自定义窗口.但是,现在同时显示了iCloud打开文件对话框和我自己的对话框.关于如何摆脱iCloud对话框的任何想法?

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?

推荐答案

我认为我会分享我对这个问题的解决方案,因为我看到其他人仍在寻找答案.这不是一个很好的解决方案,但可以解决问题.

I thought I would share my solution to this issue as I see others still looking for an answer. Its not a great solution but it does the trick.

  1. 子类NSDocumentController并添加以下内容:


+ (void) setCanOpenUntitledDocument: (BOOL) _canOpenUntitledDocument
{
    canOpenUntitledDocument = _canOpenUntitledDocument;
} // End of setCanOpenUntitledDocument:

- (void) openDocument: (id) sender
{
    // With iCloud enabled, the app keeps trying to run openDocument: on first launch (before apphasfinishedlaunching gets set.
    // This method lets us check and see if the app has finished launching or not. If we try to open a document before
    // its finished, then don't let it.
    if(!canOpenUntitledDocument)
    {
        return;
    } // End of appHasFinishedLaunching not set

    [super openDocument: sender];
} // End of openDocument:

将以下内容添加到您的应用程序委托中:

Add the following to your app delegate:


- (void) applicationDidFinishLaunching: (NSNotification *) aNotification
{
    // Finished launching. Let us open untitled documents.
    [SQLProDocumentController setCanOpenUntitledDocument: true];

    ...
}

和推理-通过在openDocument中设置一个断点,我发现在applicationDidFinishLaunchingapplicationShouldOpenUntitledFileapplicationShouldHandleReopen:hasVisibleWindows:之前调用该断点,意味着添加这些方法是没有用的.再说一次,虽然它不是很棒的代码,但是可以起作用并且可以解决问题. (没有其他解决方案对我有用).

And the reasoning -- By setting a breakpoint in openDocument I've found that its called before applicationDidFinishLaunching, applicationShouldOpenUntitledFile or applicationShouldHandleReopen:hasVisibleWindows: get called, meaning adding those methods is useless. Again, it's not great code but it works and does the trick. (None of the other solutions have worked for me).

这篇关于启用了iCloud-停止在应用程序启动时显示打开的文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆