当SMS应用程序未在后台运行时,无法在iPhone上的SMS链接中预先填充电话号码和邮件正文

DME*_*MEM 5 html iphone sms hyperlink ios

HTML允许您使用以下链接轻松与SMS应用程序进行交互:

<a href="sms:">Send a SMS</a>
Run Code Online (Sandbox Code Playgroud)

但是,不同的操作系统允许您使用以下方法预先填充电话号码和邮件正文:

<a href="sms:1234567890?body=Pre-Populted%20Message">Link</a>
Run Code Online (Sandbox Code Playgroud)

在Android上,或

<a href="sms:1234567890&body=Pre-Populted%20Message">Link</a>
Run Code Online (Sandbox Code Playgroud)

在iOS 8+上

这个问题都很好地解释了这一点.

但是我注意到iPhone上的一个问题似乎无法找到解决方案:如果SMS应用程序没有在iPhone的后台运行,点击该链接将打开SMS应用程序,但不会预先填充电话号码和消息正文在一条新消息中.

由于Google AdWords也在使用此功能,我也测试了他们的链接,但不幸的是他们遇到了同样的问题,所以我怀疑有一个解决方案,但仍然想在这里与社区核实.

DME*_*MEM 0

几年前我向苹果报告了一个错误,我相信他们从那时起就修复了它。为了支持较旧的 iOS 版本,我只应用了一个简单的脚本,该脚本将点击链接,等待半秒,然后再次点击:

<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>
Run Code Online (Sandbox Code Playgroud)

其中 openSMS.php 是:

<?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);
?>
Run Code Online (Sandbox Code Playgroud)