-2

Our project is very big and complex. It's about streaming online videos somewhere in code, or some other activities using internet (e.g, webservice, download, etc.). I am responsible to show a notification when the app starts using the 3G or 4G internet service .

Is there any library supports this feature?

Our project is written in Objective-C, supports ios8, ios9, and ios10, running on iPhone, iPad.

chipbk10
  • 5,783
  • 12
  • 49
  • 85
  • 3
    Possible duplicate of [iPhone reachability checking](http://stackoverflow.com/questions/1861656/iphone-reachability-checking) – Ollie Sep 13 '16 at 11:51
  • 1
    Unfortunately the iOS SDK does not allow you to observe the specific cellular network you are attached too. If you take a look at Apple created "Reachability" utility, this is about the maximum functionality you can expect for network conditions. https://developer.apple.com/library/ios/samplecode/Reachability/Introduction/Intro.html However, there are methods you can "guess" the speed by using the functions inside AVPlayer. You can observe for the buffer fill rate (how fast the internet is downloading bits) or playbackLIkelyToKeepUp. – TimD Sep 13 '16 at 11:53
  • @Ollie: No, it's different. The reachability is checking you have internet or not. It's not checking if your app is using internet. You app can have internet connection, but it doesn't use internet. – chipbk10 Sep 13 '16 at 11:54
  • Ah I see! I thought this line: "I am responsible to show a notification when the app starts using the 3G or 4G internet service" meant when the app starts up using the connection, not when the device actually starts using the connection. – Ollie Sep 13 '16 at 11:58
  • 1
    @chipbk10, if you look at Reachability framework it does in fact let you know if you have internet connection or not but it also tells you the "how" you are connected. It will let you know if it is Wifi or Cellular. it doesn't tell you what type of "cellular" connection you are on however. Just read the code and you will see the enums for the connection "type". specifically this line + (instancetype)reachabilityForLocalWiFi – TimD Sep 13 '16 at 11:59
  • and here is a swift version of the library https://github.com/ashleymills/Reachability.swift – TimD Sep 13 '16 at 12:00
  • @user1171911: thank you. I think my question does not deserve a minus point. – chipbk10 Sep 13 '16 at 12:06
  • I didn't down vote you.... – TimD Sep 13 '16 at 12:07

1 Answers1

3

You can detect the current connection type using CTTelephonyNetworkInfo.

The weird thing is that is not document and you will have to check the source header. It is AppStore save.

There is official documentation: https://developer.apple.com/reference/coretelephony/cttelephonynetworkinfo?language=objc

Not sure whether KVO is working on this property. There is a notification on change: CTRadioAccessTechnologyDidChangeNotification

From CTTelephonyNetworkInfo.h header:

/*
 * currentRadioAccessTechnology
 *
 * Discussion:
 *   The current radio access technology the device is registered with. May be NULL
 *   if device is not registered on any network.
 */
@property (nonatomic, readonly, retain, nullable) NSString* currentRadioAccessTechnology __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_7_0);
rckoenes
  • 69,092
  • 8
  • 134
  • 166
  • 1
    I wouldn't consider anything not in the documentation to be "App Store Safe" though. Good find in any case. And no I didn't down vote your answer.... – TimD Sep 13 '16 at 12:04
  • 2
    Well I've used it some apps and can say that anything in the public SDK should be AppStore save. There is some documentation: https://developer.apple.com/reference/coretelephony/cttelephonynetworkinfo/1616895-currentradioaccesstechnology – rckoenes Sep 13 '16 at 12:08