import
UIKit
import
MessageUI
class
ViewController
:
UIViewController
,
UINavigationControllerDelegate
,
MFMailComposeViewControllerDelegate
{
override
func
viewDidLoad() {
super
.viewDidLoad()
if
MFMailComposeViewController
.canSendMail(){
let
controller =
MFMailComposeViewController
()
controller.mailComposeDelegate =
self
controller.setSubject(
"我是邮件标题"
)
var
path =
NSBundle
.mainBundle().pathForResource(
"hangge.png"
, ofType:
""
)
var
myData =
NSData
(contentsOfFile: path!)
controller.addAttachmentData(myData, mimeType:
"image/png"
, fileName:
"swift.png"
)
controller.setMessageBody(
"我是邮件正文"
, isHTML:
false
)
self
.presentViewController(controller, animated:
true
, completion:
nil
)
}
else
{
println
(
"本设备不能发送邮件"
)
}
}
func
mailComposeController(controller:
MFMailComposeViewController
!,
didFinishWithResult result:
MFMailComposeResult
, error:
NSError
!) {
controller.dismissViewControllerAnimated(
true
, completion:
nil
)
switch
result.value{
case
MFMailComposeResultSent
.value:
println
(
"邮件已发送"
)
case
MFMailComposeResultCancelled
.value:
println
(
"邮件已取消"
)
case
MFMailComposeResultSaved
.value:
println
(
"邮件已保存"
)
case
MFMailComposeResultFailed
.value:
println
(
"邮件发送失败"
)
default
:
println
(
"邮件没有发送"
)
break
}
}
override
func
didReceiveMemoryWarning() {
super
.didReceiveMemoryWarning()
}
}
请发表评论