Nativescript accessing localhost access in android and ios

前端 未结 2 1243
北荒
北荒 2020-12-20 01:22

I have a local node rest api running on my system.

My question is ,when accessing localhost from android we are supposed to use 10.0.2.2. And When using ios we can

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-20 01:59

    Adding the typescript version of the answer

    import {platformNames} from "platform";
    import {device} from "platform";
    
      var nativePlatformLocalhost;
    
         /*in some function or globally*/
        if(device.os === platformNames.ios){
         /*localhost for ios*/
         nativePlatformLocalhost= "localhost";
       }
      else if(device.os === platformNames.android){
        /*localhost for android*/
        nativePlatformLocalhost= "10.0.2.2";
        }
    

提交回复
热议问题