I using following code to save couple of files on an iPhone app. One is a straight text file with a list of longitude and latitudes. The second file is same with KML code to display the Placemarks with the same coordinates. The code works to generate the two files as expected with .txt extensions. What I would like to do is to generate two different extensions, .txt for the straight text file and .kml for the second one. The reason for .kml extension is to be able to display those coordinates in Google Earth app on iPhone. Any help would be appreciated...
let activityViewController = UIActivityViewController(activityItems: [kml, locations], applicationActivities: nil)
present(activityViewController, animated: true, completion: nil)``
The two arrays activityViewController contain the kml and text code respectively.
This is the way I have solved it... I am sure it is not the most efficient way but it works :-). Still looking for a more efficient way as this method generates a temporary file adding to app overhead... Also, the user has to save the file twice, once for the kml and once again for the text file. So anyway, hope it helps others.
let kmlFile = "soofie_loc.kml"
let tmpDir = FileManager.default.temporaryDirectory
var fileURL : URL?
fileURL = tmpDir.appendingPathComponent(kmlFile)
let data = Data(kml.utf8)
do {
try data.write(to: fileURL! , options: .atomic)
} catch {
print(error)
}
//let activityViewController = UIActivityViewController(activityItems: [kml, locations], applicationActivities: nil)
if ( !kmlOption ) {
let activityViewController = UIActivityViewController(activityItems: [locations], applicationActivities: nil)
present(activityViewController, animated: true, completion: nil)
}
else {
let activityViewController = UIActivityViewController(activityItems: [fileURL!], applicationActivities: nil)
present(activityViewController, animated: true, completion: nil)
}