Aquí está en rápida 4 por si acaso alguien lo necesita con una UIAlert para entrar en el nombre del archivo
func handleCancel(alertView: UIAlertAction!)
{
print("Cancelled !!")
}
let alert = UIAlertController(title: "Export GPX", message: "Enter a name for the file", preferredStyle: .alert)
alert.addTextField { (textField) in
textField.text = ""
}
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler:handleCancel))
alert.addAction(UIAlertAction(title: "Done", style: .default, handler:{ (UIAlertAction) in
if alert.textFields?[0].text != nil {
let fileName = "\(String(describing: alert.textFields![0].text!)).GPX"
let path = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(fileName)
var gpxText : String = String("<?xml version=\"1.0\" encoding=\"UTF-8\"?><gpx version=\"1.1\" creator=\"yourAppNameHere\" xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:gte=\"http://www.gpstrackeditor.com/xmlschemas/General/1\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">")
gpxText.append("<trk><trkseg>")
for locations in self.locationsArray{
let newLine : String = String("<trkpt lat=\"\(String(format:"%.6f", locations.locLatitude))\" lon=\"\(String(format:"%.6f", locations.locLongitude))\"><ele>\(locations.locAltitude)</ele><time>\(String(describing: locations.locTimestamp!))</time></trkpt>")
gpxText.append(contentsOf: newLine)
}
gpxText.append("</trkseg></trk></gpx>")
do {
try gpxText.write(to: path!, atomically: true, encoding: String.Encoding.utf8)
let vc = UIActivityViewController(activityItems: [path!], applicationActivities: [])
self.present(vc, animated: true, completion: nil)
} catch {
print("Failed to create file")
print("\(error)")
}
} else {
print("There is no data to export")
}
}))
self.present(alert, animated: true, completion: {
print("completion block")
})
}
func textFieldHandler(textField: UITextField!)
{
if (textField) != nil {
textField.text = ""
}
}
No creo que el archivo GPX es leído por su aplicación, más por el propio simulador para alimentar ubicaciones en la aplicación. Hay una flecha de ubicación en Xcode en la que puede hacer clic para cargar su archivo GPX. También hay algunas ubicaciones predeterminadas que también podrías ver. –