send sms swift error

this is my code:


    func sendmessage() {
        var messageVC = MFMessageComposeViewController()
   
        messageVC.body = ""
        messageVC.recipients = [077669789805]
   
        self.presentViewController(messageVC, animated: false, completion: nil)
   
        func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult) {
            switch (result.value) {
            case MessageComposeResultCancelled.value:
                print("message was cancelled")
            case MessageComposeResultFailed.value:
                print("message failed")
                self.dismissViewControllerAnimated(true, completion: nil)
            case MessageComposeResultSent.value:
                print("message was sent")
            default:
                break;
            }
       
        }
   
    }




this is my class:


class ViewController: UIViewController, MFMessageComposeViewControllerDelegate,CLLocationManagerDelegate {


and on this line the error is:


Type 'ViewController' does bot conform to protocol ' NFMessageCompose~ViewControllerDelegate.

I think the messageComposeViewController... function needs to be outside of the sendMessage function. In other words, it should be a function of the class instance instead of a nested function.

I'm not sure what else is going on with your project, but this line is wrong:

messageVC.recipients = [077669789805]

The

recipients
property is meant to be an array of strings, so you'd have to write this:
messageVC.recipients = [ "077669789805" ]

If you need further help with this, please let us know what version of Xcode you're using. There are big differences between Xcode 6.4 and Xcode 7 beta, and it's hard to give specific answers without knowing which one you're targeting.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
send sms swift error
 
 
Q