Ios 离子2/角度-ping express服务器以防止在没有连接的情况下使用应用程序

Ios 离子2/角度-ping express服务器以防止在没有连接的情况下使用应用程序,ios,angular,express,ionic2,Ios,Angular,Express,Ionic2,我的应用程序需要连接到我们的服务器才能使用。我在应用程序组件中编写了此函数,以防止用户在服务器不可用时使用应用程序 app.component.ts pingServer(){ this.api.pingServer().subscribe(result => { if (result.success) { return true; } else { return false

我的应用程序需要连接到我们的服务器才能使用。我在应用程序组件中编写了此函数,以防止用户在服务器不可用时使用应用程序

app.component.ts

pingServer(){
    this.api.pingServer().subscribe(result => {
          if (result.success) {
            return true;
          }
          else {
            return false
          }
        },
        error=>{
          return false;
        }
        );
  }
}
这个函数只是向我们的服务器发出请求,我验证了它是否命中了正确的地址

初始化EAPP(){ console.log(“初始化”)

在服务器端:

router.get( '/ping', ( req, res, next ) => {
  return res.json( { success: true } );



} )
在浏览器上进行测试时,这种方法效果很好。但是,当使用iOS时,它表示每次ping都成功,同时,服务器没有收到请求

router.get( '/ping', ( req, res, next ) => {
  return res.json( { success: true } );



} )