samuel1991 0 Newbie Poster

Hi all, as per title.

How can I programtically determine if Cellular is disabled and no Wifi connected from my iDevice, my app will show a popup that asking for user permissions to enable cellular connection using "OK" button.

Similarly if there is no Cellular Connection (But enabled) and Wifi is disabled, then show a dialog that can bring user to the Wifi Settings page instead.

Tyvm

Dani AI

Generated

As asked by : iOS apps cannot programmatically turn the device’s Cellular or Wi‑Fi master switches on/off, nor reliably deep‑link to arbitrary system pages. The practical approach is to detect connection type + per‑app cellular permission, then guide the user (open the app’s Settings page or prompt a Wi‑Fi join). Use NWPathMonitor to detect Wi‑Fi vs Cellular, CTCellularData to detect the app’s cellular‑data restriction, and NEHotspotConfiguration when the app can programmatically request joining a specific SSID. (developer.apple.com)

Example snippets (Swift):

Detect connectivity / interface:

import Network

let monitor = NWPathMonitor()
monitor.pathUpdateHandler = { path in
  if path.status == .satisfied {
    if path.usesInterfaceType(.wifi) { /* Wi‑Fi active */ }
    else if path.usesInterfaceType(.cellular) { /* Cellular active */ }
  } else { /* no network */ }
}
monitor.start(queue: DispatchQueue(label: "net"))

Check app cellular permission:

import CoreTelephony
let cd = CTCellularData()
cd.cellularDataRestrictionDidUpdateNotifier = { state in
  /* .restricted / .notRestricted / .unknown */
}

References: NWPathMonitor and CTCellularData behavior/details. (developer.apple.com)

Opening Settings and joining Wi‑Fi:

  • The only supported in‑app link to Settings is UIApplication.openSettingsURLString (opens the app’s Settings panel). Use an alert with an “Open Settings” action that calls UIApplication.shared.open(...). (developer.apple.com)
  • For joining a known Wi‑Fi network without leaving the app, use NEHotspotConfigurationManager.shared.apply(...). This requires the Hotspot Configuration capability and explicit user consent. (developer.apple.com)

Cautions and UX tips: do not use private schemes such as prefs:root / App-Prefs:root — they trigger App Store rejection. Combine NWPathMonitor + CTCellularData to decide which alert to show, offer a single “Open Settings” button, and re‑check connectivity when the app returns to foreground. Test Wi‑Fi/Hotspot flows on a real device (simulator limitations). (stackoverflow.com)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.