It is not possible to pre-fill the phone number and message body in the SMS link on the iPhone if the SMS application does not work in the background

HTML makes it easy to interact with the SMS application using this link:

<a href="sms:">Send a SMS</a> 

However, another OS also allows you to pre-populate the phone number and message body using:

 <a href="sms:1234567890?body=Pre-Populted%20Message">Link</a> 

on Android, or

 <a href="sms:1234567890&body=Pre-Populted%20Message">Link</a> 

In iOS 8+

All of this is well explained in this matter.

However, I noticed a problem on the iPhone that I can’t find a solution for: If the SMS application does not work in the background on your iPhone, clicking on the link will open the SMS app , but will not pre-fill the phone number and message body in a new message.

Since Google AdWords uses this functionality too , I tested my links too, but unfortunately they suffer from the same problem, so I doubt this solution, but still wanted to check the community here.

+5
source share
1 answer

you should use Apple's MessageUI package

  import MessageUI 

and inside viewController write this code to send a message

  if MFMessageComposeViewController.canSendText() { let vc = MFMessageComposeViewController() vc.messageComposeDelegate = self vc.recipients = ["PHONE_NUMBER"] vc.body = "MESSAGE_BODY" self.presentVC(vc) } 

Remember to implement delegate functions // MARK: - MessageUI delegates

 extension VIEWCONTROLLER_CLASS: MFMessageComposeViewControllerDelegate, MFMailComposeViewControllerDelegate { func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) { switch result { case .cancelled: controller.dismiss(animated: true, completion: nil) case .sent: controller.dismiss(animated: true, completion: nil) case .failed: controller.dismiss(animated: true, completion: nil) } } func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) { controller.dismiss(animated: true, completion: nil) } } 
+1
source

Source: https://habr.com/ru/post/1272779/


All Articles