So I have a class that has a function to send an SMS message. I tried making the class conform to the delegate protocol...it ends up causing the class to require a type alias which I thought would be of type MFMessageViewController but that didn't work
class functions: NSObject, ObservableObject, MFMessageComposeViewControllerDelegate {
func sendInviteMessage(number: String) {
if MFMessageComposeViewController.canSendText() {
let message = MFMessageComposeViewController()
message.messageComposeDelegate = self
message.recipients = [number]
message.body = "Hi, I'd like to invite you to join my app google.com"
message.present(message, animated: true)
}
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true)
}
}
If your project use SwiftUI then you can use
UIViewControllerRepresentableusage:
Possible another solution. You can create one singleton class and present MFMessageComposeViewController on the root controller. Like this
usage: