2
votes

Crash happened on the line [[UIApplication sharedApplication] valueForKey:@"statusBar"] due to uncaught exception '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.

But nothing mentioned as how to get wifi signal strength or other status bar information like network bars. Could anyone suggest me if there is any other API's or methods to get these information?

2
Code such as [[UIApplication sharedApplication] valueForKey:@"statusBar"] has never been valid. Never attempt to dig into the private API of a class. It never ends well over time.rmaddy
Do you know any alternative to get all the information appear on iPhone status bar?Zahra W

2 Answers

1
votes
    UIStatusBarManager *statusBarManager = [UIApplication sharedApplication].keyWindow.windowScene.statusBarManager;
    if ([statusBarManager respondsToSelector:@selector(createLocalStatusBar)]) {
        UIView *_localStatusBar = [statusBarManager performSelector:@selector(createLocalStatusBar)];
        if ([_localStatusBar respondsToSelector:@selector(statusBar)]) {
            _statusBar = [_localStatusBar performSelector:@selector(statusBar)];
            NSLog(@"🌶%@",[[[[_statusBar valueForKey:@"_statusBar"] valueForKey:@"_currentAggregatedData"] valueForKey:@"_wifiEntry"] valueForKey:@"displayValue"]);
        }
    }
0
votes
    id statusBar;
    if (@available(iOS 13.0, *)) {
        UIStatusBarManager *statusBarManager = [UIApplication sharedApplication].keyWindow.windowScene.statusBarManager;
        if ([statusBarManager respondsToSelector:@selector(createLocalStatusBar)]) {
            UIView *localStatusBar = [statusBarManager performSelector:@selector(createLocalStatusBar)];
            if ([localStatusBar respondsToSelector:@selector(statusBar)]) {
                statusBar = [localStatusBar performSelector:@selector(statusBar)];
            }
        }

        if (statusBar) {
            id currentData = [[statusBar valueForKeyPath:@"_statusBar"] valueForKeyPath:@"currentData"];
            id wifiEntry = [currentData valueForKeyPath:@"wifiEntry"];
            id cellularEntry = [currentData valueForKeyPath:@"cellularEntry"];
            if (wifiEntry && [[wifiEntry valueForKeyPath:@"isEnabled"] boolValue]) {
                signalStrength = [[wifiEntry valueForKeyPath:@"displayValue"] intValue];
                signalStrength = signalStrength == 3 ? 4 : signalStrength;
            } else if (cellularEntry && [[cellularEntry valueForKeyPath:@"isEnabled"] boolValue]) {
                signalStrength = [[cellularEntry valueForKey:@"displayValue"] intValue];
            }
        }
        return signalStrength;
    }