2

In my app I'm trying to open up a MFMessageComposeViewController in order for the user to send a SMS message. I have a View Controller that is a messaging delegate and part of a Navigation Controller, and this class then calls the view controller like this:

@IBAction func sendMessage(sender: AnyObject) {
    var messageVC = MFMessageComposeViewController()

    messageVC.body = "Hey!"
    messageVC.recipients = ["\(((sender as! UITableViewCell).viewWithTag(1) as! UILabel).text!)"]
    messageVC.messageComposeDelegate = self
    self.presentViewController(messageVC, animated: true, completion: nil)
}

This all works OK, and the message sends. My didFinishWithResult implementation then looks like this:

func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult) {
    switch result.value {
        case MessageComposeResultCancelled.value:
            println("Message was cancelled")
            controller.dismissViewControllerAnimated(true, completion: nil)

        case MessageComposeResultFailed.value:
            println("Message failed")
            controller.dismissViewControllerAnimated(true, completion: nil)

        case MessageComposeResultSent.value:
            println("Message was sent")
            controller.dismissViewControllerAnimated(false, completion: nil)

        default:
            break
    }
}

Which is what I've seen recommended. However, this removes all my views from the screen and leaves it all black. I understand that this has something to do with the fact I'm pushing this MFMessageComposeViewController onto the navigation stack then dismissing it, but how can I get around this?

I've tried so many variants (like presenting instead, trying to pop to root afterwards, etc.) but to no avail. I'm starting to think you're just not meant to do this with a navigation controller.

Any ideas at all would be greatly appreciated!

fanfan
  • 504
  • 1
  • 4
  • 13

0 Answers0