David Peat
David Peat

Reputation: 254

iOS 13- How can I open another app and pass it a file?

I have a drawing app, and due to some heavy structural change (mostly PencilKit) I'm implementing a brand new app for version 2. Documents created by version 1 will be read-only in version 2.

I've implemented UIActivityViewController in both versions so I can successfully move a document from version 1 to version 2. What I'd like to do though is offer another option of directly opening a version 1 document in version 2 without the activity view controller popping up. I'm sharing via file URL, and I see how to implement opening an app via URL scheme, but I'm not sure if I can open via URL scheme AND have the URL be both a custom scheme and also a file reference.

Upvotes: 0

Views: 930

Answers (1)

David Peat
David Peat

Reputation: 254

I was able to get this to work by using an AppGroup containing both my old & new applications. That gave me a shared area to save & retrieve files. Once I registered both apps with the app group in Xcode, I could write files to the shared directory like this:

    if let sharedURL = fileManager.containerURL(forSecurityApplicationGroupIdentifier: "group.mycompany.appgroupname") {   <read or write the files in here> }

I then opened a custom URL which contained the path to the file, or the term "ALL_FILES" for example, "myapp://private/where/apple/put/my/files/file1.ext". or "myapp://ALL_FILES" and the new app would parse the URL to decide what to do.

Upvotes: 1

Related Questions