0

I need in my application to get continuously strength of WiFi. I am trying to implement Key-Value Observing approach and get this info from StatusBar this way:

  [UIApplication.sharedApplication()  addObserver:signalListener
                                         forKeyPath:@"IDontKnowWhat"
                                            options:NSKeyValueObservingOptionNew
                                            context:NULL]; 

But this gives me error:

Called object type 'UIApplication * _Nonnull' is not a function or function pointer

And later I would like to get signal strength this way:

    NSArray *subviews = [[[IDontKnowWhat valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];
    NSString *wifiNetworkItemView = nil;    

    for (id subview in subviews) {

        if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {
            wifiNetworkItemView = subview;
        }
    }
    int wifiSignalStrength = [[wifiNetworkItemView valueForKey:@"wifiStrengthRaw"] intValue];

Can someone give me advise, if it is possible to implement KVO on statusBar of UIApplication sharedApplication? Or is there any other way to get continuously WiFi strength?

Vladimír
  • 701
  • 1
  • 7
  • 24
  • Probably duplicates [this question](https://stackoverflow.com/questions/44167577/using-private-api-to-read-wifi-rssi-value/48083845#48083845) – fewlinesofcode Oct 12 '18 at 09:43
  • @llb But it does not solves live updating if the WiFi signal. – Vladimír Oct 12 '18 at 10:16
  • 1
    `UIApplication.sharedApplication()` is a syntax error. It should be `UIApplication.sharedApplication`. (It's not Swift either, because Swift would be `UIApplication.shared`.) – Michael Oct 13 '18 at 19:48

1 Answers1

0

It seems like Apple is not supporting general use Wifi Strength analysis. However, there is a unorthodox method to get signal strength. NEHotspotHelper has a signalStrength property that was designed for users to connect to hotspots.

https://forums.developer.apple.com/thread/67932

Jae Yang
  • 479
  • 3
  • 13