I’m attempting to jot down an IOS software which accepts PDF paperwork from different purposes.
I succeeded in writing an app which works on Xcode iPhone emulator. However once I push my software to an actual iPhone system, the iPhone proposes me my software within the checklist of purposes the place I can ship the PDF, however when choosing it, the applying opens, however doesn’t course of the doc.
To realize this, I declare my App with a DocumentGroup:
@fundamental
struct ScannerImporterApp: App {
var physique: some Scene {
DocumentGroup(newDocument: ScannerImporterDocument()) { file in
ContentView(doc_name: file.doc.title, doc_content: file.doc.textual content)
}
WindowGroup {
ContentView(doc_name: "", doc_content: "")
}
}
}
Then, I declare my class which manages the doc as is :
extension UTType {
static var exampleText: UTType {
UTType(importedAs: "com.adobe.pdf")
}
}
struct ScannerImporterDocument: FileDocument
{
var textual content: String
var title: String
init(title: String = "My title", textual content: String = "Hi there, world!")
{
print("TestDocument : init")
self.title = title
self.textual content = textual content
}
static var readableContentTypes: [UTType] { [.exampleText] }
init(configuration: ReadConfiguration) throws {
print("TestDocument : init 2")
let information = configuration.file.regularFileContents
title = configuration.file.filename!
textual content = (information?.base64EncodedString())!
}
func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
print("TestDocument : init 3")
let information = textual content.information(utilizing: .utf8)!
return .init(regularFileWithContents: information)
}
}
With this code, when executed in iPhone emulator, the applying is exhibiting a file selector view when it’s opened. And if the consumer sends a PDF to this app from one other app, this pdf is managed by the app by creating a brand new ScannerImporterDocument, and offering its content material in “configuration” variable.
However when executed on actual iPhone, is reveals a file selector view when open, but it surely doesn’t react to different apps sending a pdf to it (when such motion is finished, the one result’s that the applying is proven in foreground, however nonetheless with file selector.
Any concept how I can clear up this difficulty ?
Word that I don’t must show the file selector view when opening the app. So, if there’s one other resolution with out utilizing the DocumentGroup, it may be OK for me too.
Many thanks,
Brice