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.
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.
Comments