zoukankan      html  css  js  c++  java
  • ionic项目中实现发短信和打电话

    原文地址:http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/ionic-sms-and-call/

    最近做的一个ionic项目中需要实现发短信和打电话,总结了一下遇到的问题和实现的方法。

    1.关于打电话

    html中可以很方便的实现拨打电话先在config.xml中添加:

    <access origin="tel:*" launch-external="yes"/>
    

    然后在html中这样写:

    <a href="tel:10086”>拨打电话10086</a>

    但是我想获取点击打电话的时间,所以做了改动:

    html中:

    <button ng-click="callFriend($event, friend)"></button>

    js中:

    $scope.callFriend = function ($event, friend) {
       window.open('tel:' + friend.PhoneNumber);
       //获取打电话的时间
       var time=new Date();
    }

    有时不想要自动识别电话,为了防止电话识别,可以在头文件中添加这一句:

    <meta name="format-detection" content="telephone=no">

    2.关于发短信,是使用的ng-cordova的插件$cordovaSMS:

    先添加该插件:

    cordova plugin add https://github.com/cordova-sms/cordova-sms-plugin.git

    记得相应的要在app.js中依赖ng-cordova,在发送短信的控制器中依赖$cordovaSms

    我实现的是点击发短信的按钮会弹出一个popup:

    在html中添加点击事件:

    <button ng-click="openSendMessage(phoneNumber)"></button>

    在控制器中写发送短信的函数:

    //打开发送短信的popup
    $scope.openSendMessage = function (phonenumber) {
      $rootScope.sendMessagePopup.show(phonenumber)
        .then(function (result) {
          return result;
        });
    };
    
    $scope.sms = {
      number: ‘10086’,
      message: '生日快乐'
    };
    var options = {
      replaceLineBreaks: false, // true to replace 
     by a new line, false by default
      android: {
        intent: '' // send SMS with the native android SMS messaging
        //intent: '' // send SMS without open any other app
        //intent: 'INTENT' // send SMS inside a default SMS app
      }
    };
    $scope.sendSMS = function () {
      $cordovaSms.send(‘10086’, '生日快乐', options)
        .then(function () {
          alert('发送短信成功');
        }, function (error) {
          alert('发送短信失败');
        });
    };
  • 相关阅读:
    jq 切换功能toggle
    打开控制台F12弹出弹窗
    CSS解决无空格太长的字母,数字不会自动换行的问题
    微信公众号页面无法唤起输入框
    别人遇到的两条前端面试题
    在HTML打开已安装的App,未安装跳转到对应的下载链接
    promise的使用
    特殊的json对象转数组,最合成新的json数据
    Rem兼容知多少?
    parseInt的结果看不懂,请看我分析
  • 原文地址:https://www.cnblogs.com/panda-zhang/p/5343638.html
Copyright © 2011-2022 走看看