-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathMailerManager.swift
53 lines (42 loc) · 1.75 KB
/
MailerManager.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// MailerManager.swift
// OpenGpxTracker
//
// Created by merlos on 21/09/14.
// Copyright (c) 2014 TransitBox. All rights reserved.
//
import Foundation
import UIKit
import MessageUI
class MailerManager: NSObject, MFMailComposeViewControllerDelegate {
var composer: MFMailComposeViewController!
var controller: UIViewController
init(controller: UIViewController) {
self.controller = controller
super.init()
}
func send(filepath: String) {
composer = MFMailComposeViewController()
composer.mailComposeDelegate = self
// set the subject
composer.setSubject("[Open GPX tracker] Gpx File")
// Add some text to the message body
var body = "Open GPX Tracker \n is an open source app for Apple devices. Create GPS tracks and export them to GPX files."
composer.setMessageBody(body, isHTML: true)
let fileData: NSData = NSData.dataWithContentsOfFile(filepath, options: .DataReadingMappedIfSafe, error: nil)
composer.addAttachmentData(fileData, mimeType: "application/gpx+xml", fileName: filepath.lastPathComponent)
// Display the comopser view controller
controller.presentViewController(composer, animated: true, completion: nil)
}
func mailComposeController(controller: MFMailComposeViewController!,
didFinishWithResult result: MFMailComposeResult,
error: NSError!) {
switch result.value {
case MFMailComposeResultSent.value:
println("Email sent")
default:
println("Whoops")
}
controller.dismissViewControllerAnimated(true, completion: nil)
}
}