This is sort of a part two for my text file exporting and importing dilemma. Right now, I have the write code and export code. The final pieces to the puzzle is import code and read code. I want to take an attachment from an email and import it into the app, so I can read it. I have the basic read code:
@IBAction func readButton(_ sender: UIButton) {
let filePath = getDocumentsDirectory().appendingPathComponent("matrixFile.txt")
do {
try displayField.text = String(contentsOfFile: path!,
encoding: String.Encoding.utf8)
} catch let error as NSError{
displayField.text = String(describing: error)
}
}
But I was also wondering what filePath would be when importing. I adjusted the info.plist for exportation, but would I need to make any more changes to that? Here are my current additions: Thanks in advance.
In order for you to open a document coming in via e-mail attachment, you would need to have your application appear in the Open in ... menu list. As per the relevant Apple Documentation you have to:
I know you have added the Exported Type UTI already (as shown in your screenshot) but did you follow the instructions on the above linked page to add a Document Type using the UTI you defined? If you didn't, you should add the Document Type as well since, I believe, it's the Document Type which identifies that your app as being able to handle that particular type of document.
Also, since txt is a known format, you probably don't need to define the UTI again for text files. You might be able to just use the existing UTI for text files in your Document Type definition.
In fact, I tested the above by creating a quick test app and all I had to add to the app was the Document Type, (without a UTI definition since text is a known type) in order for me to see my test app in the Open in... list. Here's my Document Type declaration:
Update: As @LeoDabus mentions, you do need to implement actually opening the file via the
UIApplicationDelegate
'sapplication(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool
method. I figured you were aware of this part, but if you need additional help with this, do ask here and I'll respond.