3

I am working on an application which will call the web services using WiFi as well as cellular data of iPhone. My application is working fine on WiFi and 3G network but it is not working in 4G network. So please tell me how do I detect whether app is connected through 3g or 4G and how do I resolve problem related to 4G network.

Any help would be appreciable. Thanks in advance.

Sandeep Patidar
  • 147
  • 2
  • 11

1 Answers1

1

here it is same issue and may be bellow code of example is helps you. Using private APIs, you can read this information directly in the status bar.

https://github.com/nst/MobileSignal/blob/master/Classes/UIApplication+MS.m

+ (NSNumber *)dataNetworkTypeFromStatusBar {

    UIApplication *app = [UIApplication sharedApplication];

    UIStatusBar *statusBar = [app valueForKey:@"statusBar"];

    UIStatusBarForegroundView *foregroundView = [statusBar valueForKey:@"foregroundView"];

    NSArray *subviews = [foregroundView subviews];

    UIStatusBarDataNetworkItemView *dataNetworkItemView = nil;

    for (id subview in subviews) {
        if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {
            dataNetworkItemView = subview;
            break;
        }
    }

    return [dataNetworkItemView valueForKey:@"dataNetworkType"];
}

Credit goes to :-

Determining 3G vs Edge

Objective-C determine data network type of the iOS device

Community
  • 1
  • 1
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
  • i need this result when my app is in background – Patel Jigar Oct 29 '15 at 07:15
  • @Nitin Gohel, I think it is a private api so may be rejected by apple. Is it approve your app by apple using above code? please suggest me so I can idea regarding this before upload app on apple store. – Nikunj Jadav Nov 26 '15 at 13:46
  • hum may be and now its too many changes from apple side – Nitin Gohel Nov 26 '15 at 13:47
  • Not a good suggestion to use private API and it doesn't really addresses the question. The root of the issue is to figure out why it doesn't work on 4G. – DevGansta Aug 18 '16 at 14:50