How to check internet connection in alamofire?

For swift 5 and Alamofire 5.4.4 ,I created a swift class called Connectivity . Use NetworkReachabilityManager class from Alamofire and configure the isConnectedToInternet() method as per your need. import Foundation import Alamofire class Connectivity { class func isConnectedToInternet() -> Bool { return NetworkReachabilityManager()?.isReachable ?? false } } Usage: if Connectivity.isConnectedToInternet() { print(“Yes! internet is available.”) … Read more

How to detect Network Signal Strength in iOS Reachability

My original thought was to time the download of a file, and see how long it takes: @interface ViewController () <NSURLSessionDelegate, NSURLSessionDataDelegate> @property (nonatomic) CFAbsoluteTime startTime; @property (nonatomic) CFAbsoluteTime stopTime; @property (nonatomic) long long bytesReceived; @property (nonatomic, copy) void (^speedTestCompletionHandler)(CGFloat megabytesPerSecond, NSError *error); @end @implementation ViewController – (void)viewDidLoad { [super viewDidLoad]; [self testDownloadSpeedWithTimout:5.0 completionHandler:^(CGFloat megabytesPerSecond, … Read more

Reachability Guide for iOS

I have implemented Reachability like this. Download https://developer.apple.com/library/content/samplecode/Reachability/Introduction/Intro.html and add Reachability.h and .m to your project. Add the SystemConfiguration framework to your project. #import “Reachability.h” where you want to use it. Use this code. -(BOOL)reachable { Reachability *r = [Reachability reachabilityWithHostName:@”enbr.co.cc”]; NetworkStatus internetStatus = [r currentReachabilityStatus]; if(internetStatus == NotReachable) { return NO; } return YES; … Read more

Detecting Network Connectivity Changes using Reachability, NSNotification and Network Link Conditioner in Swift

You must create a Reachability object before you can receive notifications from it. Also, be sure to call the startNotifier() method on the Reachability object you create. This would be an example of how to do so inside of your application delegate: class AppDelegate: UIResponder, UIApplicationDelegate { private var reachability:Reachability!; func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: … Read more

iPhone reachability checking

From your screen shot, it seems like you do not have Reachability added to your project. You must download Reachability from Apple: https://developer.apple.com/library/content/samplecode/Reachability/Introduction/Intro.html And add both .h and .m files to your project. Update: You noted you have Reachability. But looking at the most recent version, I can see why you have the errors you … Read more

iOS Detect 3G or WiFi

Using the code that Apple has provided here Reachability *reachability = [Reachability reachabilityForInternetConnection]; [reachability startNotifier]; NetworkStatus status = [reachability currentReachabilityStatus]; if(status == NotReachable) { //No internet } else if (status == ReachableViaWiFi) { //WiFi } else if (status == ReachableViaWWAN) { //3G }

Check for internet connection with Swift

For Swift 3, Swift 4 (working with cellular and Wi-Fi): import SystemConfiguration public class Reachability { class func isConnectedToNetwork() -> Bool { var zeroAddress = sockaddr_in(sin_len: 0, sin_family: 0, sin_port: 0, sin_addr: in_addr(s_addr: 0), sin_zero: (0, 0, 0, 0, 0, 0, 0, 0)) zeroAddress.sin_len = UInt8(MemoryLayout.size(ofValue: zeroAddress)) zeroAddress.sin_family = sa_family_t(AF_INET) let defaultRouteReachability = withUnsafePointer(to: &zeroAddress) … Read more