Ad hoc App Distribution no Wifi connection?

Hello,

I distributed an App through Ad hoc and was able to install the app through the web server I set up.

In my app I need a network connection. But my error handling always tells me that I have no internet connection.

Is it possible that there is no Network connection for apps that are distributed through Ad hoc?

Thank you for your help

Regards, Tell

Hey @Relbot,

Thanks for posting this on the forums!

I am not a code expert, but we will need a code sample to help find out why your application is failing to determine if it has an active network connection.

I can tell you that regardless of how your application is signed (Development or AdHoc) that it does have access to the network by default to make calls outside of its container.

Hopefully this helps!

Your app's network connectivity should not be affected by the distribution method.

What platform does your app use?

  • iOS?
  • macOS?
  • tvOS?
  • watchOS?

my error handling always tells me that I have no internet connection

The first question is, does your app really have no internet connection, or is there an issue with your error handling code?

If you could share your error handling code, and the details of how you are using the network connection, forum users may be able to help you.

Hello @robnotyou and @ChuckMN. Thx for both answering so fast :)

Yes the problem is with my checking of the internet connection

This is my code:

public class InternetReachability {



    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) {

            $0.withMemoryRebound(to: sockaddr.self, capacity: 1) {zeroSockAddress in

                SCNetworkReachabilityCreateWithAddress(nil, zeroSockAddress)

            }

        }



        var flags: SCNetworkReachabilityFlags = SCNetworkReachabilityFlags(rawValue: 0)

        if SCNetworkReachabilityGetFlags(defaultRouteReachability!, &flags) == false {

            return false

        }



        let isReachable = flags == .reachable

        let needsConnection = flags == .connectionRequired



        return isReachable && !needsConnection

    }

}

The code above only works if I plug my phone in my computer and directly compline onto my phone, but not through ad hoc

If I change the code to this both distributions work perfectly, but why does the above one doesn't work for ad hoc

public class InternetReachability {



    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) {

            $0.withMemoryRebound(to: sockaddr.self, capacity: 1) {zeroSockAddress in

                SCNetworkReachabilityCreateWithAddress(nil, zeroSockAddress)

            }

        }



        var flags: SCNetworkReachabilityFlags = SCNetworkReachabilityFlags(rawValue: 0)

        if SCNetworkReachabilityGetFlags(defaultRouteReachability!, &flags) == false {

            return false

        }





        let isReachable = (flags.rawValue & UInt32(kSCNetworkFlagsReachable)) != 0

        let needsConnection = (flags.rawValue & UInt32(kSCNetworkFlagsConnectionRequired)) != 0

        let ret = (isReachable && !needsConnection)



        return ret



    }

}

Is there a reason for making this so complicated, or do you just need to check for network connectivity?

Have you considered monitoring your network connectivity using NWPathMonitor?

For example, to monitor WiFi and Cellular:

var monitorWiFi = NWPathMonitor(requiredInterfaceType: .wifi)
var monitorCellular = NWPathMonitor(requiredInterfaceType: .cellular)
    
var isInternetAvailableOnWiFi: Bool = false
var isInternetAvailableOnCellular: Bool = false

Then...

    /// **startPathMonitors**
    /// Monitor the WiFi and Cellular connections
    /// Note: NWPathMonitor checks for connection to wider network
    ///
    func startPathMonitors() {
        /// WiFi
        monitorWiFi.pathUpdateHandler = { path in
            /// This closure is called every time the connection status changes
            DispatchQueue.main.async {
                switch path.status {
                case .satisfied:
                    print("PathMonitor WiFi satisfied, interface: \(path.availableInterfaces) gateways: \(path.gateways)")
                default:
                    print("PathMonitor WiFi not satisfied: \(path.unsatisfiedReason)")
                }
                self.isInternetAvailableOnWiFi = (path.status == .satisfied)
            }
        }
        monitorWiFi.start(queue: DispatchQueue(label: "monitorWiFi"))
        
        /// Cellular
        monitorCellular.pathUpdateHandler = { path in
            /// This closure is called every time the connection status changes
            DispatchQueue.main.async {
                print("PathMonitor Cellular: \(path.status)")
                self.isInternetAvailableOnCellular = (path.status == .satisfied)
            }
        }
        monitorCellular.start(queue: DispatchQueue(label: "monitorCellular"))
    }
Ad hoc App Distribution no Wifi connection?
 
 
Q