I use swift language and I have problem with text message code, when I run the application and I press on SMS button, it takes me to compose a SMS to here is ok. But when I press cancel to get back to the app doesn't go !! Only deleting what I wrote in messaging area!! AND when I press home button to get out off message and try to open the app, it's taking me to the last point!! (Text messages). So I need help with code that get me back to the app when I need to cancel sending SMS.
I sorted out now,by adding delegate protocol to the class and message delegate method
import UIKit
import MessageUI BY ADDING MF-DELEGATE PROTOCOL TO THE CLASS
class ViewController: UIViewController, MFMessageComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func sendMessage(sender: AnyObject) {
let messageVC = MFMessageComposeViewController()
messageVC.body = " "
messageVC.recipients = [ tel-Nomber]
messageVC.messageComposeDelegate = self
presentViewController(messageVC, animated: true, completion: nil)
}
// AND BY ADDING THE LAST CODE // Message Delegate method//!!!!
func messageComposeViewController(controller: MFMessageComposeViewController, didFinishWithResult result: MessageComposeResult) {
switch result.rawValue {
case MessageComposeResultCancelled.rawValue :
print("message canceled")
case MessageComposeResultFailed.rawValue :
print("message failed")
case MessageComposeResultSent.rawValue :
print("message sent")
default:
break
}
controller.dismissViewControllerAnimated(true, completion: nil)
}
}