在游戏中使用xcode 7 beta3中的精灵套件发送电子邮件?
我正在用xcode 7beta3中的swift制作一个精灵套件中的iPad游戏,我希望在游戏完成后将游戏结果发送给用户电子邮件。用户应按下一个名为“发送”的按钮,并重定向到他们可以键入电子邮件地址并发送消息的位置。但我不知道如何制作和发送电子邮件 我一直在互联网上搜索这个问题的答案,但都是旧版本的答案。我希望你能帮忙 提前谢谢 编辑: 我一直在寻找更多的,我发现了一个解决方案(这里:),但我仍然有一个问题。在我的GameViewController中,我添加了:在游戏中使用xcode 7 beta3中的精灵套件发送电子邮件?,xcode,swift,email,sprite-kit,xcode7-beta3,Xcode,Swift,Email,Sprite Kit,Xcode7 Beta3,我正在用xcode 7beta3中的swift制作一个精灵套件中的iPad游戏,我希望在游戏完成后将游戏结果发送给用户电子邮件。用户应按下一个名为“发送”的按钮,并重定向到他们可以键入电子邮件地址并发送消息的位置。但我不知道如何制作和发送电子邮件 我一直在互联网上搜索这个问题的答案,但都是旧版本的答案。我希望你能帮忙 提前谢谢 编辑: 我一直在寻找更多的,我发现了一个解决方案(这里:),但我仍然有一个问题。在我的GameViewController中,我添加了: override func vi
override func viewDidLoad() {
super.viewDidLoad()
let scene = StartGameScene(size: view.bounds.size)
let skView = view as! SKView
skView.showsFPS = true
skView.showsNodeCount = true
skView.ignoresSiblingOrder = true
scene.scaleMode = .ResizeFill
skView.presentScene(scene)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
internal func sendEmail() {
//Check to see the device can send email.
if( MFMailComposeViewController.canSendMail() ) {
print("Can send email.")
let mailComposer = MFMailComposeViewController()
mailComposer.mailComposeDelegate = self
//Set the subject and message of the email
mailComposer.setSubject("Have you heard a swift?")
mailComposer.setMessageBody("This is what they sound like.", isHTML: false)
if let filePath = NSBundle.mainBundle().pathForResource("Math", ofType: "txt") {
print("File path loaded.")
if let fileData = NSData(contentsOfFile: filePath) {
print("File data loaded.")
mailComposer.addAttachmentData(fileData, mimeType: "text/plain", fileName: "Math")
}
}
self.presentViewController(mailComposer, animated: true, completion: nil)
}
}
func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
self.dismissViewControllerAnimated(true, completion: nil)
}
当您按下按钮时,sendMail()将在我的一个游戏场景中调用。
问题是我按下那个按钮时出错了。它打印出来了
你可以发送电子邮件。
已加载文件路径。
已加载文件数据
这是应该的,但它给出了一个错误:
无法将“UIView”(0x1964ea508)类型的值强制转换为“SKView”(0x19624f560)
我认为问题在于self.presentViewController(),但我不知道如何修复它