Get information about the status bar: network type, operator, battery level, displayed system time, and moreImport UIKitEnumNetworktype {CaseNetworkstatesnoneNo networkCasenetworkstates2g2GCasenetworkstates3g3GCasenetworkstates4g4GCaseNetworkstateswifiWIFI}ClassStatusbarinfo:NSObject {Get Carrier nameClassFuncServicecompany ()String {Let array:Nsarray = (Uiapplication.sharedapplication (). Valueforkeypath ("StatusBar")? Valueforkeypath ("Foregroundview")? Subviews)!For infoIn array {If Info.iskindofclass (Nsclassfromstring ("Uistatusbarserviceitemview")!) {Let Serverstr:String = Info.valueforkeypath ("Servicestring")as!StringReturn SERVERSTR}}Return"" }Show System timeClassFuncCurrenttimestring ()String {Let array:Nsarray = (Uiapplication.sharedapplication (). Valueforkeypath ("StatusBar")? Valueforkeypath ("Foregroundview")? Subviews)!For infoIn array {If Info.iskindofclass (Nsclassfromstring ("Uistatusbartimeitemview")!) {Let Timestr:String = Info.valueforkeypath ("TimeString")as!StringReturn TIMESTR}}Return"" }Detecting Network statusClassFuncCurrentnetworktype ()Networktype {Let array:Nsarray = (Uiapplication.sharedapplication (). Valueforkeypath ("StatusBar")? Valueforkeypath ("Foregroundview")? Subviews)!var states:Networktype =.NetworkstatesnoneFor infoIn array {If Info.iskindofclass (Nsclassfromstring ("Uistatusbardatanetworkitemview")!) {Let Networktype = Info.valueforkeypath ("Datanetworktype")!. IntegerValueSwitch (networktype) {Case0:states =.Networkstatesnone;No network modeBreakCase1:states =.networkstates2g;BreakCase2:states =.networkstates3g;BreakCase3:states =.networkstates4g;BreakCase5:states =.Networkstateswifi;BreakDefaultBreak } } }Return states}Get current battery informationClassFuncCurrentbatterypercent ()string {let array: NSArray = (uiapplication.sharedapplication (). Valueforkeypath ( "StatusBar")? Valueforkeypath ( "Foregroundview")? Subviews)! for info in array {if Info.iskindofclass (nsclassfromstring ( " Uistatusbarbatterypercentitemview ")!) {let presentstr:string = Info.valueforkeypath (" percentstring ") as! string return Presentstr}} return ""}}
Swift-Get status bar some information