Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

DMEM

HTML allows you to easily interact with the SMS app using this link:

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

However different OS allows you to also 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>

On iOS 8+

This is all well explained in this question.

However I noticed a problem on iPhones that I can't seem to find a solution for: If the SMS app is not running in the background on your iPhone, clicking the link will open the SMS app but will not pre-populate the phone number and message body in a new message.

Since Google AdWords are using this functionality too, I tested their links too but unfortunately they are suffering from the same problem, so I doubt there is a solution out there but still wanted to check with the community here.

DMEM

I reported a bug to Apple a few years ago and I believe they fixed it since. To support older iOS versions, I just applied a simple script that will hit the link, wait half a second and then hit it again:

<html>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<a href="#" onclick="window.open('openSMS.php?number=5556667777&text=TEXT_TO_PRE_POPULATE');
                      wait(500);
                      window.open('openSMS.php?number=5556667777&text=TEXT_TO_PRE_POPULATE');">
Click here to open the SMS app
</a>
    
</body>
</html>

where openSMS.php is:

<?php

        // Include and instantiate the class.
        require_once 'Mobile-Detect-2.8.25/Mobile_Detect.php';
        $detect = new Mobile_Detect;
        
        // Get parameters
        $number = $_GET['number'];
        $text = $_GET['text'];
        $url;
         
        // Check for a specific platform with the help of the magic methods:
        if( $detect->isiOS() ){
            $url = "sms:" . $number . "&body=" . $text;         
        } else if( $detect->isAndroidOS() ){
            $url = "sms:" . $number . "?body=" . $text;
        } else if ($detect->isMobile()){
            $url = "sms:" . $number . "?body=" . $text;
        } else {
            
        }
        
        header('Location: '.$url);
?>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Sending SMS programmatically without opening message app

How to pre-populate the sms body text via an html link

How can I make a website button open up an SMS compose to a phone number?

Launch default SMS app without a message

How to launch SMS Message app

Can non-default SMS app ALWAYS receive broadcast when SMS received, even when force closed?

Android Service to receive SMS when app is in background

Android Send sms when app not running in background

Sending a SMS message using AWS Pinpoint to a specific phone number

SMS verification : what if user phone number changed?

Twilio - How to send bulk sms with a different body text per phone number?

How to read incoming SMS in a ReactNative app when app is not running?

How can i send sms notification to 200 phone number and subscribe them to a topic in SNS

How to know SMS number and phone number is the same?

How to send SMS to different Phone number

Sending sms from background in windows phone

How to get phone number from contacts to my SMS app

sending a location link as sms in background

Sending SMS Message from Android App

How get the sms Body for a message tracking?

Sending an SMS with Swift, remember phone number

Link to SMS app does not open in Android mail

SMS received broadcastReceiver is not called when app is not running

How to determine the email to sms gateway address of any phone number when using sms code verification

Pre-populate the sms body text with an https url

Android Espresso Testing with phone number (sms) authentication

Invalid from phone number in Twilio SMS gateway

Can I use a phone number instead of a Sender ID when sending SMS with Amazon SNS?

how can I send 4 digit sms code to a phone number in compose kotlin?