Showing
2 changed files
with
6 additions
and
1 deletions
| @@ -133,10 +133,15 @@ export class NetworkManager { | @@ -133,10 +133,15 @@ export class NetworkManager { | ||
| 133 | * 同步获取网络类型,耗时 | 133 | * 同步获取网络类型,耗时 |
| 134 | */ | 134 | */ |
| 135 | public getNetTypeSync(): NetworkType { | 135 | public getNetTypeSync(): NetworkType { |
| 136 | + try { | ||
| 136 | let netHandle = connection.getDefaultNetSync(); | 137 | let netHandle = connection.getDefaultNetSync(); |
| 137 | let netCapabilities = connection.getNetCapabilitiesSync(netHandle) | 138 | let netCapabilities = connection.getNetCapabilitiesSync(netHandle) |
| 138 | this.reset(netCapabilities.bearerTypes) | 139 | this.reset(netCapabilities.bearerTypes) |
| 139 | return this.networkType; | 140 | return this.networkType; |
| 141 | + } catch (e) { | ||
| 142 | + Logger.error(TAG, 'getNetTypeSync e: ' + JSON.stringify(e)) | ||
| 143 | + } | ||
| 144 | + return NetworkType.TYPE_UNKNOWN | ||
| 140 | } | 145 | } |
| 141 | 146 | ||
| 142 | private parseData(data: connection.NetCapabilityInfo) { | 147 | private parseData(data: connection.NetCapabilityInfo) { |
| @@ -43,7 +43,7 @@ export class NetworkUtil { | @@ -43,7 +43,7 @@ export class NetworkUtil { | ||
| 43 | */ | 43 | */ |
| 44 | static isNetConnected(): boolean { | 44 | static isNetConnected(): boolean { |
| 45 | let type = NetworkManager.getInstance().getNetType() | 45 | let type = NetworkManager.getInstance().getNetType() |
| 46 | - if (type == NetworkType.TYPE_NONE) { | 46 | + if (type == NetworkType.TYPE_UNKNOWN || type == NetworkType.TYPE_NONE) { |
| 47 | return false | 47 | return false |
| 48 | } | 48 | } |
| 49 | return true | 49 | return true |
-
Please register or login to post a comment