Skip to content

Instantly share code, notes, and snippets.

View KevinJue's full-sized avatar

Kevin Jue KevinJue

  • Budget-Box
  • Rouen
View GitHub Profile
@KevinJue
KevinJue / DetectConnectionDevice.swift
Created March 13, 2015 22:25
Detect device connection (WIFI / 3G / 4G ) and retrieve carrier name if needed
import SystemConfiguration
import CoreTelephony
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(sizeofValue(zeroAddress))
zeroAddress.sin_family = sa_family_t(AF_INET)
let defaultRouteReachability = withUnsafePointer(&zeroAddress) {