获取网络状态

来源:互联网 发布:登陆艇升级数据经验值 编辑:程序博客网 时间:2024/06/01 07:39

UIApplication * app =[UIApplication sharedApplication];

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

    

    int type = 0;

    for (id child in children) {

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

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

        }

    }

    //0 - 无网络; 1 - 2G; 2 - 3G; 3 - 4G; 5 - WIFI

    NSLog(@"网络状态----%d",type);


0 0
原创粉丝点击