Tôi đang cố gắng thiết lập ứng dụng có tùy chọn gửi email.Gửi email từ swift 3
tôi có mã này:
import Foundation
import MessageUI
import UIKit
class emailClass: UIViewController, MFMailComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
if !MFMailComposeViewController.canSendMail() {
print("Mail services are not available")
return
}
sendEmail()
}
func sendEmail() {
let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self
// Configure the fields of the interface.
composeVC.setToRecipients(["[email protected]"])
composeVC.setSubject("Hello!")
composeVC.setMessageBody("Hello this is my message body!", isHTML: false)
// Present the view controller modally.
self.present(composeVC, animated: true, completion: nil)
}
func mailComposeController(controller: MFMailComposeViewController,
didFinishWithResult result: MFMailComposeResult, error: NSError?) {
// Check the result or perform other tasks.
// Dismiss the mail compose view controller.
controller.dismiss(animated: true, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Vì vậy, tôi nhận được tin nhắn này: "Dịch vụ thư không có sẵn". Bây giờ tôi đã đăng nhập vào thiết bị mô phỏng trong iCloud ... Vì vậy, tôi nghĩ rằng nó nên làm điều đó nhưng nó không phải. Tại sao điều này không hoạt động? Bạn có thể cho tôi biết điều gì sai và làm thế nào tôi có thể tiến lên?
Bạn có cấu hình thiết bị của bạn với một địa chỉ email? nếu không, thì hãy làm ... và nó có thể giải quyết vấn đề của bạn. –
Tôi đang sử dụng trình mô phỏng. Tôi làm cách nào để định cấu hình thiết bị bằng địa chỉ email? khi tôi đi đến cài đặt tôi không thể thấy tùy chọn "email" .... –
Tôi điều, bạn đã giải quyết vấn đề này .. Trong khi đó, đây là liên kết để định cấu hình email cho thiết bị iOS ... https: // support. apple.com/en-in/HT201320 –