From caab93240f3e5216c3752b8034868f2da87d07a1 Mon Sep 17 00:00:00 2001 From: jon b Date: Sun, 27 Mar 2016 06:37:49 +0000 Subject: [PATCH] Added reachability (check wifi vs 3g) --- reachability.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 reachability.py diff --git a/reachability.py b/reachability.py new file mode 100644 index 0000000..f2772d5 --- /dev/null +++ b/reachability.py @@ -0,0 +1,20 @@ +# coding: utf-8 +from objc_util import * + +NSBundle.bundleWithPath_('/System/Library/PrivateFrameworks/SoftwareUpdateServices.framework').load() + +def currentNetworkType(): + ''' 0: none + 1: wifi + 2+: cellular''' + netMon=ObjCClass('SUNetworkMonitor').sharedInstance() + return netMon.currentNetworkType() +def main(): + networkType=currentNetworkType() + assert networkType>0, 'Network Not Connected' + if networkType>1: + ok_to_continue=raw_input('Using cellular data. Continue downloading? [y/n]') + assert ok_to_continue.lower()=='y', 'User Cancelled' + +if __name__=='__main__': + main()