Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Referencing the bencoding.network module
var benCodingNetwork = require('bencoding.network');
Ti.API.info("Create a new Carrier Info Object");
var carrierInfo = benCodingNetwork.createCarrierInfo();
Ti.API.info("Get carrier name => " + carrierInfo.carrierName);
Ti.API.info("Get mobile country code => " + carrierInfo.mobileCountryCode);
Ti.API.info("Get mobile network code => " + carrierInfo.mobileNetworkCode);
Ti.API.info("Get ISO country code for cellular service provider => " + carrierInfo.isoCountryCode);
Ti.API.info("Mobile service provider supports VOIP => " + carrierInfo.allowsVOIP);
Ti.API.info("Create a new Current Network Info Object");
var currentNetwork = benCodingNetwork.createCurrentNetwork();
Ti.API.info("Get SSID => " + currentNetwork.SSID);
Ti.API.info("Get BSSID => " + currentNetwork.BSSID);
Ti.API.info("Create a new Reachability Object");
var reachability = benCodingNetwork.createReachability();
Ti.API.info("Get reachabilityWithHostName => " + reachability.reachabilityWithHostName("www.apple.com"));
Ti.API.info("Get reachabilityForLocalWiFi => " + reachability.reachabilityForLocalWiFi());
var hostReachableByType = reachability.hostNameReachableBy("www.apple.com");
function getReachableType(findType){
var results = "Oops something went wrong";
if(findType==reachability.NETWORK_STATUS_NOT_REACHABLE){
results="Not Reachable";
}
if(findType==reachability.NETWORK_STATUS_WIFI){
results="WiFi Network";
}
if(findType==reachability.NEWORK_STATUS_WWAN){
results="Mobile Network";
}
return results;
};
var reachableType=getReachableType(hostReachableByType);
Ti.API.info("Reachable via => " + reachableType);
@juncoding

This comment has been minimized.

Copy link

@juncoding juncoding commented Sep 9, 2014

Hi Ben,
I tried to use function reachability.reachabilityWithHostName, but met below error, could you please advise?
Thank you very much.

  • ZJ

Built with TiSDK 3.2.3.GA

[INFO] : Create a new Reachability Object
[ERROR] : Script Error {
[ERROR] : backtrace = "#0 () at file:///Users/zhoujun/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/2994286B-E7DD-49D8-8523-A9AB23CB560F/Test.app/alloy.js:231";
[ERROR] : line = 133;
[ERROR] : message = "invalid method (createReachability) passed to BencodingNetworkModule";
[ERROR] : sourceId = 361180448;
[ERROR] : sourceURL = "file:///Users/zhoujun/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/2994286B-E7DD-49D8-8523-A9AB23CB560F/Test.app/alloy/controllers/index.js";
[ERROR] : }
[WARN] : Attempted to load BencodingNetworkReachabilityProxy: Could not find class definition.

@albert0m

This comment has been minimized.

Copy link

@albert0m albert0m commented Sep 24, 2014

same thing here. I recompiled it from the sources but the problem above is still there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment