ip地址设备信息

其实是个小问题,在项目中遇到要获取手机ip地址和mac地址的问题,mac地址获取用appcan的uexDevice插件可以实现。

但是ip地址,获取的方式很多,具体有搜狐/腾讯/新浪等提供的接口。但是考虑到实用性,以及编码格式问题。最终项目选用得还是搜狐的。

实现就不多说了。

  1. <script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>  
  2.     <script type="text/javascript">  
  3.         $("#nowip").val(returnCitySN.cip);  
  4.     </script>  
document.addEventListener("deviceready", function() { BD.gUID = $cordovaDevice.getUUID(); }, false);
console.log("apprun:" + BD.gUID);
console.log("ip:" + returnCitySN.cip);
console.log("id:" + returnCitySN.cid);
console.log("name:" + returnCitySN.cname);
 
  1. 一、添加命令:

    [javascript] view plain copy
     
    1. cordova plugin add cordova-plugin-device  

    二、相关js代码,同时也是官网上的代码为:

    [javascript] view plain copy
     
    1. module.controller('MyCtrl', function($scope, $cordovaDevice) {  
    2.   
    3.   document.addEventListener("deviceready", function () {  
    4.   
    5.     var device = $cordovaDevice.getDevice();  
    6.   
    7.     var cordova = $cordovaDevice.getCordova();  
    8.   
    9.     var model = $cordovaDevice.getModel();  
    10.   
    11.     var platform = $cordovaDevice.getPlatform();  
    12.   
    13.     var uuid = $cordovaDevice.getUUID();  
    14.   
    15.     var version = $cordovaDevice.getVersion();  
    16.   
    17.   }, false);  
    18. })  
原文地址:https://www.cnblogs.com/xfcao/p/7216510.html