this code must be changed as there‘s no longer a status bar or status bar window.

简介: this code must be changed as there‘s no longer a status bar or status bar window.

ModalName: 文件日志, ErrorLevel: Error, Function: UncaughtExceptionHandler, Line: 227, Format: <- 2021-04-19 15:59:36 ->[ Uncaught Exception ]

Name: NSInternalInconsistencyException, Reason: App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there’s no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead.

[ Fe Symbols Start ]

0 CoreFoundation 0x0000000187881880 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 1202304

1 libobjc.A.dylib 0x000000019c89ac50 objc_exception_throw + 60

2 CoreFoundation 0x0000000187787000 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 176128

3 Foundation 0x0000000188b1b91c 7698BF3E-0CF6-31C0-85E9-562714F01276 + 518428

4 UIKitCore 0x000000018a23e068 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 12386408

5 UIKitCore 0x000000018a23e55c 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 12387676

6 Foundation 0x0000000188aa8f14 7698BF3E-0CF6-31C0-85E9-562714F01276 + 48916

7 稚美家长端 0x0000000104d56000 -[BITSingleObject getNetWorkStatesWithStatus:] + 248

8 稚美家长端 0x0000000104c0c3ec __38-[PPBizModule monitoringNetworkStatus]_block_invoke + 344

9 稚美家长端 0x0000000104ca1600 __47-[AFNetworkReachabilityManager startMonitoring]_block_invoke + 148

10 稚美家长端 0x0000000104ca1cc0 __AFPostReachabilityStatusChange_block_invoke + 80

11 libdispatch.dylib 0x0000000105f9bbcc _dispatch_call_block_and_release + 32

12 libdispatch.dylib 0x0000000105f9d6c0 _dispatch_client_callout + 20

13 libdispatch.dylib 0x0000000105facf34 _dispatch_main_queue_callback_4CF + 1000

14 CoreFoundation 0x00000001877fd11c 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 659740

15 CoreFoundation 0x00000001877f7120 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 635168

16 CoreFoundation 0x00000001877f621c CFRunLoopRunSpecific + 600

17 GraphicsServices 0x000000019f3c0784 GSEventRunModal + 164

18 UIKitCore 0x000000018a236ee8 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 12357352

19 UIKitCore 0x000000018a23c75c UIApplicationMain + 168

20 稚美家长端 0x0000000104bea330 main + 140

21 libdyld.dylib 0x00000001874b66b0 21B19919-1334-38BC-B233-896E929945E0 + 5808

[ Fe Symbols End ]

原因分析:

// iOS 13 弃用keyWindow属性 从所有windowl数组中取

代码修改例子:

//请注意:该函数只有在显示状态栏的页面才能获取到2G/3G/4G网络
- (BGNetworkReachabilityStatus)getNetWorkStatesWithStatus : (AFNetworkReachabilityStatus)status
{
    if(AFNetworkReachabilityStatusUnknown == status)
    {
        return BGNetworkReachabilityStatusUnknown;
    }
    else if(AFNetworkReachabilityStatusNotReachable == status)
    {
        return BGNetworkReachabilityStatusNotReachable;
    }
    else if(AFNetworkReachabilityStatusReachableViaWiFi == status)
    {
        return BGNetworkReachabilityStatusReachableViaWiFi;
    }else if (@available(iOS 12.1, *))
    {
        return  [self getNetType];
    }
//    if(LL_iPhoneX)
//    {
//        return BGNetworkReachabilityStatusReachableViaWWAN;
//    }
    UIApplication *app = [UIApplication sharedApplication];
//    NSArray *children = [[[app valueForKeyPath:@"statusBar"]valueForKeyPath:@"foregroundView"]subviews];
    NSArray *children;
    // 不能用 [[self deviceVersion] isEqualToString:@"iPhone X"] 来判断,因为模拟器不会返回 iPhone X
//    NSLog(@"%@   %@", [[app valueForKeyPath:@"_statusBar"] valueForKeyPath:@"_statusBar"], [[[app valueForKeyPath:@"_statusBar"] valueForKeyPath:@"_statusBar"] valueForKeyPath:@"_statusBar.currentData"]);
    if (@available(iOS 13.0, *))
    {
        return BGNetworkReachabilityStatusReachableViaWWAN;
    }
    else
    {
        if ([[app valueForKeyPath:@"_statusBar"] isKindOfClass:NSClassFromString(@"UIStatusBar_Modern")]) {
            children = [[[[app valueForKeyPath:@"_statusBar"] valueForKeyPath:@"_statusBar"] valueForKeyPath:@"foregroundView"] subviews];
        }
        else
        {
            children = [[[app valueForKeyPath:@"_statusBar"] valueForKeyPath:@"foregroundView"] subviews];
            
    //        if ([[app valueForKeyPath:@"_statusBar"] isKindOfClass:NSClassFromString(@"UIStatusBar_Modern")]) {
    //            id curData = [statusBar valueForKeyPath:@"statusBar.currentData"];
    //            BOOL wifiEnable = [[curData valueForKeyPath:@"_wifiEntry.isEnabled"] boolValue];
    //            BOOL cellEnable = [[curData valueForKeyPath:@"_cellularEntry.isEnabled"] boolValue];
    //            // iPhone X上通过StatusBar只能获取到网络是WiFi还是蜂窝网
    //            // 当网络为蜂窝网的时候,无法获取到具体的网络状态
    //            if (wifiEnable) {
    //                states = @"WiFi";
    //            } else if (cellEnable) {
    //                states = @"Cellular";
    //            }

        }
        int netType = 0;
        //获取到网络返回码
        for (id child in children) {
            if ([child isKindOfClass:NSClassFromString(@"UIStatusBarDataNetworkItemView")]) {
                //获取到状态栏
                netType = [[child valueForKeyPath:@"dataNetworkType"]intValue];
                
                switch (netType) {
                    case 0:
                    {
                        NSLog(@"无网络");
                        //无网模式
                        return BGNetworkReachabilityStatusNotReachable;
                    }
                        break;
                    case 1:
                    {
                        NSLog(@"2G");
                        return BGNetworkReachabilityStatusReachableViaWWAN2G;
                    }
                        break;
                    case 2:
                    {
                        NSLog(@"3G");
                        return BGNetworkReachabilityStatusReachableViaWWAN3G;
                    }
                        break;
                    case 3:
                    {
                        NSLog(@"4G");
                        return BGNetworkReachabilityStatusReachableViaWWAN4G;
                    }
                    case 4:
                    {
                        NSLog(@"5G");
                        return BGNetworkReachabilityStatusReachableViaWWAN5G;
                    }
                        break;
                    case 5:
                    {
                        NSLog(@"wifi");
                        return BGNetworkReachabilityStatusReachableViaWWAN5G;
                    }
                        break;
                    default:
                        break;
                }
            }
            //根据状态选择
            return BGNetworkReachabilityStatusReachableViaWWAN;
        }
    }
  
    return BGNetworkReachabilityStatusReachableViaWWAN;
}
目录
相关文章
|
11月前
|
编译器 Serverless Go
Fail to start function, Code:1
Fail to start function, Code:1
62 2
|
11月前
|
JavaScript
Uncaught runtime errors: × ERROR Avoided redundant navigation to current location: “/xxx“.
Uncaught runtime errors: × ERROR Avoided redundant navigation to current location: “/xxx“.
154 0
|
Linux
error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
104 0
|
测试技术
SAP IDoc 报错- Function module not allowed SPEIDOC_INPUT_DESADV1 –
SAP IDoc 报错- Function module not allowed SPEIDOC_INPUT_DESADV1 –
SAP IDoc 报错- Function module not allowed SPEIDOC_INPUT_DESADV1 –
Unable to add window --token is not valid
Unable to add window --token is not valid