-1

I am trying to make an ios app, where the app must work in intranet connection only, and if tried to hit api endpoint from different network, the app should show alert dialog. I tried working with apple's reachability code.. I dont have host name but ip of my host case scenario:

when connected to different network, it says not connected and api call also fails.. what needs to be

but when connected to same network, the endpoint is giving me success response, but the reachibility still says, not connected

thanks in advance

Ashwin Shrestha
  • 518
  • 3
  • 17

2 Answers2

0

It sounds like your connection is working fine, but you're troubling of getting indication whether you connected or not.

You can

  1. Pinging to local "server" using Simple Ping see here
  2. Use Reachability for local Wifi and check the Wifi name (a.k.a. SSID) see an example here
Benny Davidovitz
  • 1,152
  • 15
  • 18
0

Add this file to your project:

then configure your AppDelegate

  • in application:didFinishLaunchingWithOptions: method

    let reach = Reachability()
    reach.monitorReachabilityChanges()
    
    NotificationCenter.default.addObserver(self, selector: #selector(AppDelegate.networkStatusChanged(_:)), name: NSNotification.Name(rawValue: ReachabilityStatusChangedNotification), object: nil)
    
  • then Add this method

     func networkStatusChanged(_ notification: Notification) {
        let userInfo = (notification as NSNotification).userInfo
        guard let status = userInfo?["Status"] as? String else { return }
        if status.lowercased().contains("online") {
            //CONNECTED
        } else {
            //NOT CONNECTED
        }
    }
    
iAmrSalman
  • 621
  • 8
  • 9