zoukankan      html  css  js  c++  java
  • 直接读取状态栏上信息获取网络状态-可以扩展获取电量运营商等信息

    直接读取状态栏上信息获取网络状态-可以扩展获取电量运营商等信息

    -(NSString *)getNetWorkStates{

        UIApplication *app = [UIApplication sharedApplication];

        NSArray *children = [[[app valueForKeyPath:@"statusBar"]valueForKeyPath:@"foregroundView"]subviews];

        NSString *state = nil;

        int netType = 0;

        for (id child in children) {

            if ([child isKindOfClass:NSClassFromString(@"UIStatusBarDataNetworkItemView")]) {

                netType = [[child valueForKeyPath:@"dataNetworkType"]intValue];

                switch (netType) {

                    case 0:

                        state = @"无网络";

                        break;

                    case 1:

                        state = @"2G";

                        break;

                    case 2:

                        state = @"3G";

                        break;

                    case 3:

                        state = @"4G";

                        break;

                    case 5:

                        state = @"WIFI";

                        break;

                    default:

                        break;

                }

            }

        }

        return state;

    }

  • 相关阅读:
    Typora的使用
    selenium中webdriver提供的八大定位元素方法
    JAVA的Data和Timestamp的相互转换
    Jmeter设置参数作为断言依据
    Springboot +Poi 导入Excel表格
    window.location.reload();
    带参数的链接跳转
    Layui结束时间不能小于开始时间
    后台返回数据渲染Layui表格
    Layui中layedit模板的使用
  • 原文地址:https://www.cnblogs.com/zhujin/p/4015422.html
Copyright © 2011-2022 走看看