While this works fine in the Simulator, on device, when my custom keyboard extension tries to open a UIDocument in the shared container written by the containing app, it fails to do so. The following is logged to the Console:
2019-05-10 15:39:09.640305-0700 TagManagerKeyboard[15249:1890026] [claims] 528516A6-B168-43EA-8AAF-B7B1754EE42E grantAccessClaim message failed: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.FileCoordination was invalidated." UserInfo={NSDebugDescription=The connection to service named com.apple.FileCoordination was invalidated.}
2019-05-10 15:39:09.640891-0700 TagManagerKeyboard[15249:1890026] A process invoked one of the -[NSFileCoordinator coordinate...] methods but filecoordinationd crashed. Returning an error.
The error reported to UIDocument.handleError(:userInteractionPermitted:) is not very helpful:
Error Domain=NSCocoaErrorDomain Code=256 "The file “MyFile” couldn’t be opened." UserInfo={NSURL=file:///private/var/mobile/Containers/Shared/AppGroup/3A486D56-F897-4B13-A09F-0B4183686E2C/MyFile}
I open the document in viewDidLoad()
of my UIInputViewController
subclass:
if let container = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.mycompany.MyApp")
{
let containerPath = Path(container.path)
let file = containerPath + "MyFile"
self.doc = MyDocument(fileURL: file.url)
debugLog("Extension doc at \(file)")
self.doc.open
{ (inSuccess) in
debugLog("Opened doc: \(inSuccess)")
NotificationCenter.default.post(name: .dataUpdated, object: nil)
}
}
This crash occurs 100% of the time. RequestsOpenAccess
is YES
in the Info.plist. And again, this works in the simulator. I also tried it on an iOS 9.5.3 iPad I have, and it has a similar crash.
Any ideas why it crashes on device?