Cocoa 聚光灯插件读取文件导致;“拒绝文件写入数据”;控制台中的错误

Cocoa 聚光灯插件读取文件导致;“拒绝文件写入数据”;控制台中的错误,cocoa,nsdocument,appstore-sandbox,spotlight,spotlight-plugin,Cocoa,Nsdocument,Appstore Sandbox,Spotlight,Spotlight Plugin,我有一个基于NSDocument的沙盒应用程序,带有一个Spotlight插件来索引我的自定义文档 在测试过程中,我注意到Spotlight插件在索引文档时将许多错误记录到控制台: 5/4/15 3:11:18.765 PM sandboxd[432]: ([579]) mdworker(579) deny file-write-data /Users/test/Desktop/test.document (import fstype:hfs fsflag:480D000 flags

我有一个基于NSDocument的沙盒应用程序,带有一个Spotlight插件来索引我的自定义文档

在测试过程中,我注意到Spotlight插件在索引文档时将许多错误记录到控制台:

5/4/15 3:11:18.765 PM sandboxd[432]: ([579]) mdworker(579) deny file-write-data 
  /Users/test/Desktop/test.document 
  (import fstype:hfs fsflag:480D000 flags:240000005E diag:0 isXCode:0
    uti:com.test.document 
  plugin:/TestApp.app/Contents/Library/Spotlight/TestApp Spotlight Importer.mdimporter - 
  find suspect file using: sudo mdutil -t 407144)
插件似乎试图写入其索引的文件(尽管它只有只读访问权限)

在我的Spotlight插件实现中,我没有做任何特别的事情来写入文档。我只需初始化NSDocument子类以从文档中读取:

[[TTCustomDocument alloc] initWithContentsOfURL:url ofType:contentType error:outError];
以下是堆栈跟踪:

Thread 4:
0   libsystem_kernel.dylib          0x00007fff9015ee92 __mac_syscall + 10
1   libsystem_sandbox.dylib         0x00007fff910140b0 sandbox_check + 206
2   AppKit                          0x00007fff8f75fc38 -[NSDocument _autosavingPossibilityConcern] + 213
3   AppKit                          0x00007fff8f75fb02 -[NSDocument _checkAutosavingPossibilityAndReturnError:] + 60
4   AppKit                          0x00007fff8f75f9cf -[NSDocument _checkAutosavingAndReturnError:] + 26
5   AppKit                          0x00007fff8f75f97e -[NSDocument _checkAutosavingAndUpdateLockedState] + 26
6   AppKit                          0x00007fff8f75e420 -[NSDocument _initWithContentsOfURL:ofType:error:] + 319
7   AppKit                          0x00007fff8f75e056 -[NSDocument initWithContentsOfURL:ofType:error:] + 230
看起来自动保存检查以某种方式试图写入文档

我能做些什么吗?是否存在某种只读模式来打开NSO文档

更新:

复制:

  • 创建新的Xcode项目:“Cocoa基于文档的应用程序”
  • 添加聚光灯插件
  • NSDocument实现和Spotlight插件的代码如下:

  • 好的,
    -[TTCustomDocument initWithContentsOfURL:ofType:error:
    或任何其他自定义初始化代码的代码在哪里,以及您的
    -readFromURL:ofType:error
    和相关代码?很可能您正从其中一个(init…和/或read…)方法触发某些内容,导致文档被标记为脏(具有未保存的更改),从而触发自动保存系统。这是
    TTCustomDocument
    类中的不正确行为


    我猜您正在触发某个事件,该事件在文档的撤消管理器中注册了更改。如果它是一个核心数据文档,并且您正在设置一些初始数据,那么很容易做到;如果您以调用自己的一种支持撤消的漏斗方法的方式设置初始数据,那么也很容易做到。最简单的解决方法(文档推荐)是调用
    [self.undoManager disableundowregistration]更改前和“[self.undoManager enableUndoRegistration];在更改之后和返回自我之前。

    感谢您的关注。我没有用contentsofURL:ofType:error:
    重写
    initWithContentsOfURL:ofType:error。在
    init
    中,我设置了一些内部对象。阅读内容时,我确实使用了
    [self.undoManager disableundowregistration]
    。查看堆栈跟踪,我认为它正在立即检查文档是否可以自动保存。我重写了
    +(BOOL)autosavesInPlace
    以返回YES。我使用基于Xcode文档应用程序模板的示例应用程序复制了这一点。只有当
    autosavesInPlace
    返回YES时,才会出现问题。我将提交一份bug报告,看看苹果公司对此有何评论。哪些内部对象?你如何设置它们?这些都是关键的细节。我在问题中添加了相关代码的要点。