App keeps being told to open nonexistent doc on launch
App keeps being told to open nonexistent doc on launch
- Subject: App keeps being told to open nonexistent doc on launch
- From: Jens Alfke <email@hidden>
- Date: Mon, 19 Oct 2015 10:25:29 -0700
I’ve got a weird problem in an OS X app project I’m dusting off after a long hiatus. Every time the app launches, it pops up error alerts saying it can’t open two documents. The underlying problem is that the files for those documents don’t exist (and they have weird paths that are down inside the project’s build directory.) Apparently somehow NSDocumentController is remembering those ancient files as part of the app’s state and is telling my NSDocument class to reopen them on launch.
I can’t find any way to stop this from happening. My NSDocument subclass correctly returns NO and a file-not-found error from its -readFromURL:ofType:error method, but this doesn’t cause the nonexistent file to be removed from the app’s state.
- I’ve used ‘defaults delete’ to delete the app’s defaults
- I’ve deleted the app’s Application Support directory
- I’ve deleted ~/Library/Saved Application State/my-bundle-id.savedState
- I’ve deleted ~/Library/Preferences/my-bundle-id.LSSharedFileList.plist
- I’ve searched ~/Library for any other filename containing the app’s bundle ID but didn’t find any
- I’ve tried checking the “Launch app without persistent state restoration” checkbox in the scheme’s Options panel
Where the @&%$ is this stale state being saved? And why won’t it go away even though the file clearly doesn’t exist?
—Jens
PS: I’m on OS X 10.11. But I saw this same problem briefly the last time I tried running this project back on 10.10.
PPS: Here’s the backtrace of my NSDocument class being told to open the file:
* frame #0: 0x0000000100008b1f Viewer`-[DBDocument readFromURL:ofType:error:](self=0x000060c0000421c0, _cmd="readFromURL:ofType:error:", absoluteURL=@"Test_AppList -- file:///Work/Viewer/build/Viewer/Build/Products/Debug/", typeName=@“generic", outError=domain: nil - code: 105827994372816) + 1919 at DBDocument.m:36
frame #1: 0x00007fff9e2d341a AppKit`-[NSDocument _initWithContentsOfURL:ofType:error:] + 171
frame #2: 0x00007fff9e2d3306 AppKit`-[NSDocument initWithContentsOfURL:ofType:error:] + 230
frame #3: 0x00007fff9e3bf406 AppKit`-[NSDocumentController makeDocumentWithContentsOfURL:ofType:error:] + 627
frame #4: 0x00007fff9e5ed96a AppKit`__97-[NSDocumentController makeDocumentWithContentsOfURL:alternateContents:ofType:completionHandler:]_block_invoke + 85
frame #5: 0x00007fff9e5ed908 AppKit`-[NSDocumentController makeDocumentWithContentsOfURL:alternateContents:ofType:completionHandler:] + 225
frame #6: 0x00007fff9e3be2cf AppKit`__80-[NSDocumentController openDocumentWithContentsOfURL:display:completionHandler:]_block_invoke + 635
frame #7: 0x00007fff9e5ec8d9 AppKit`__144-[NSDocumentController _coordinateReadingAndGetAlternateContentsForOpeningDocumentAtURL:resolvingSymlinks:thenContinueOnMainThreadWithAccessor:]_block_invoke_2952 + 182
frame #8: 0x00007fff9e5ec7eb AppKit`__144-[NSDocumentController _coordinateReadingAndGetAlternateContentsForOpeningDocumentAtURL:resolvingSymlinks:thenContinueOnMainThreadWithAccessor:]_block_invoke951 + 221
frame #9: 0x00007fff9e5ec652 AppKit`__144-[NSDocumentController _coordinateReadingAndGetAlternateContentsForOpeningDocumentAtURL:resolvingSymlinks:thenContinueOnMainThreadWithAccessor:]_block_invoke_4 + 346
frame #10: 0x00007fff8dbcf4dc CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden