I have a sharing extension that accepts URLs. When I use the Google
app on iOS, in certain circumstances, it provides a file with a type identifier public.plain-text
. However, when I try to decode that as plain text, e.g., using (item
below is an NSItemProvider
):
item.loadFileRepresentation(forTypeIdentifier: "public.plain-text") { (url, error) in
if let error = error {
logger.error("\(error)")
return
}
guard let url = url else {
logger.error("No url found")
return
}
guard let data = try? Data(contentsOf: url) else {
logger.error("No data loaded from URL")
return
}
guard let string = String(data: data, encoding: .utf8) else {
logger.error("No string loaded from URL; data.count: \(data.count); \(data)")
return
}
logger.debug("string from text file: \(string)")
}
This fails on the conversation to a .utf8 String.
What is the format of this file? And what does it contain?