启用iCloud的 - 停止打开的文件显示在应用程序启动?(iCloud enabled - Sto

2019-07-04 23:41发布

我刚刚加入iCloud的支持,我的工作在一个应用程序。 它的工作的伟大,只是当我在焦点打开应用程序没有文件出现在iCloud中打开文件对话框,我不希望它!

在我的应用程序的委托,我有:

- (BOOL) applicationShouldOpenUntitledFile:(NSApplication *)sender
{
    [mainWindowController.window makeKeyAndOrderFront:self];
    return NO;
}

我用它来展现自己的自定义窗口。 但是现在,都显示无论是icloud的打开文件对话框和我自己的对话框。 我如何能摆脱iCloud的对话框的任何想法?

Answer 1:

https://developer.apple.com/library/prerelease/content/releasenotes/AppKit/RN-AppKitOlderNotes/index.html

NSDocument支持iCloud的

在10.8,NSDocument基于具有普遍性容器的标识符权利增益的新功能和UI应用程序,以方便的iCloud文件管理。

当iCloud的启用和应用程序第一次运行或重新激活,没有窗户是不是创建一个新的无标题文档可见或正在恢复,NSDocumentController会显示出用户的iCloud库非模态打开面板。

...

不希望使用这些功能,任何或所有NSDocument的子类的应用程序可以重写+ NSDocument usesUbiquitousStorage]和返回NO。 如果所有应用程序的声明NSDocument子类从这个方法没有返回,然后NSDocumentController绝不会显示新的非模态打开面板。

所以,如果你可以放弃使用本发行说明中列出的功能, return NO+[NSDocument usesUbiquitousStorage] 我确认你仍然可以打开/从正常对话将文件保存到iCloud中存储。



Answer 2:

在应用程序委托把下面的代码可以让你绕过的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];
    }
}


Answer 3:

- (BOOL) applicationShouldOpenUntitledFile:(NSApplication *)sender
{
    [mainWindowController.window makeKeyAndOrderFront:self];
    return NO;
}

这部分是正确的。 我只是测试它。

只要确保你的这个类是真的是你的应用程序代理。

  1. 建立一个叫做prefixAppDelegate新类
  2. 在你MainMenu.xib ,将一个新的对象到一边,并设置它的自定义类的应用程序委托类
  3. 右键单击应用程序 ,并从代表向下拖动到应用程序委托对象。
  4. 现在只要将代码粘贴到上面您的应用程序委托类

如果仍然没有帮助,尝试登录的东西applicationShouldOpenUntitledFile:

另外,我建议不要设置[mainWindowController.window makeKeyAndOrderFront:self]; 在此方法。 你还是使用应用程序的委托方法applicationDidFinishLaunching:方法。



Answer 4:

我的观察和修正:[applicationShouldOpenUntitledFile:]将不会被执行,除非你删除键NSDocumentClass从* -info.plist。 但是,这是有害的,如果你的应用程序是基于申请文件,它不会打开您链接的文档类型。

我的解决方法是直接打开我的自定义窗口-(void)applicationWillFinishLaunching:(NSNotification *)notification方法(应用程序代理)

ETDocumentWindowController *windowController =  (ETDocumentWindowController*)get your own window controller here...;
[windowController.window makeKeyAndOrderFront:nil];


Answer 5:

我想我会分享我解决这个问题,因为我看到别人还在寻找一个答案。 它不是一个很好的解决方案,但它的伎俩。

  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:

以下添加到您的应用程序代理:


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

    ...
}

和推理-通过设置在断点openDocument我发现它之前调用applicationDidFinishLaunchingapplicationShouldOpenUntitledFileapplicationShouldHandleReopen:hasVisibleWindows:被调用,意义添加这些方法是无用的。 再次,这不是很大的代码,但它的工作原理和做的伎俩。 (其他解决方案都没有为我工作)。



Answer 6:

我遇到了类似的问题-原来,在我的情况,我不得不删除NSDocumentClass从我中的Info.plist键和值CFBundleDocumentTypes阵列。 只有这样, applicationShouldOpenUntitledFile:方法被调用,从而让我避免的iCloud /文档窗口中打开。



文章来源: iCloud enabled - Stop the open file displaying on application launch?