如何获得用户IP地址,确保用户在离子\\科尔多瓦在线 [英] How to get User Ip address and check that user is online in Ionic\Cordova

查看:412
本文介绍了如何获得用户IP地址,确保用户在离子\\科尔多瓦在线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作离子框架和科尔多瓦。我想提出一些数据到服务器
但是当这两个条件都满足
1.设备联机。
2.数据(提交)是可用的。

我检查这个科尔多瓦网络插件文档但我搞不清是有它太多的怪癖。我怎么能写有效code为所有设备(Android的手段,赢手机,IPhone等),还我怎样才能得到用户的IP地址?
我已经试过,工作在浏览器不错,但不敢来实现事业的手机可以忽略这条线(我猜)

  $ scope.checkOnline = navigator.onLine;


解决方案

这很容易,你只需要使用两个科尔多瓦插件这样的:


  1. 插件1:科尔多瓦-插件-的NetworkInterface

例如:

  networkinterface.getIPAddress(功能(IP){
    警报(IP);
});

工作的例子,教程,点击 这里

<醇开始=2>
  • 插件2:科尔多瓦 - 插件网络信息

  • 例如:

      document.addEventListener(在线,onOnline,FALSE);功能onOnline(){
        //处理在线活动
    }

    插件文档,请点击这里

    I am working on Ionic Framework and cordova. I want to submit some data to server but when these two condition are satisfied 1. device is online. 2. data (to submit) is available .

    i am checking this cordova network plugin documentation but i am confuse that there is too many quirks in it. How can i write valid code for all devices(means android, win Phone, IPhone etc..) and also how can i get user IP Address.?? i have tried this, working fine in browser but afraid to implement cause mobile phone can ignore this line (i guess)

    $scope.checkOnline = navigator.onLine;
    

    解决方案

    It's easy, you only need to use two Cordova plugins for this:

    1. Plugin 1: cordova-plugin-networkinterface

    Example:

    networkinterface.getIPAddress(function (ip) { 
        alert(ip); 
    });
    

    Working example and tutorial, click here.

    1. Plugin 2: cordova-plugin-network-information

    Example:

    document.addEventListener("online", onOnline, false);
    
    function onOnline() {
        // Handle the online event
    }
    

    Plugin documentation, click here.

    这篇关于如何获得用户IP地址,确保用户在离子\\科尔多瓦在线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆