How to open iMessage from iOS app on UIButton Tap?

Swift 4 and above-

 

@IBAction func imessageClicked(_ sender: Any) {

        guard let messageAppURL = NSURL(string: "sms:")
            else { return }
        if UIApplication.shared.canOpenURL(messageAppURL as URL) {
            UIApplication.shared.open(messageAppURL as URL, options: [:], completionHandler: nil)
        }
    }
Back to Top