FRAMEWORK/CORDOVA

Cordova 네트워크 접속 확인

나나나나나나나ㅏ나난ㄴ나ㅏ나나 2020. 2. 25. 14:57
728x90

환경

  • macOS Catalina
  • cordova 9.0.0
  • cordova platform android 9.0.0

plugin 설치

cordova plugin add cordova-plugin-network-information

 

사용방법

 

if(navigator.connection.type == Connection.NONE){
	console.log('인터넷 연결이 되지 않음 :( ');
}else{
	console.log('인터넷 연결 되어있음 /0/');
}

 

위와 같이 쉽게 사용할 수 있으며 navigator.connection.type 을 출력했을 때 나오는 값은 다음과 같습니다

Connection.UNKNOWN  //  Unknown connection
Connection.ETHERNET //  Ethernet connection
Connection.WIFI     //  WiFi connection
Connection.CELL_2G  //  Cell 2G connection
Connection.CELL_3G  //  Cell 3G connection
Connection.CELL_4G  //  Cell 4G connection
Connection.CELL     //  Cell generic connection
Connection.NONE     //  No network connection

 

참고 및 출처

https://riptutorial.com/ko/cordova/example/12451/cordova-plugin-network-information-%ED%94%8C%EB%9F%AC%EA%B7%B8%EC%9D%B8-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0

 

728x90