-
Notifications
You must be signed in to change notification settings - Fork 0
/
iOSUtils.swift
41 lines (34 loc) · 1.36 KB
/
iOSUtils.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import Foundation
import UIKit
import SystemConfiguration
class iOSUtils {
class func getUserId() -> String {
return (UIDevice.current.identifierForVendor?.uuidString)!
}
class func getSystemInfo() -> String {
let systemName = UIDevice.current.systemName
let systemVersion = UIDevice.current.systemVersion
return "\(systemName) \(systemVersion)"
}
class func getSDKVersion() -> String {
return "iOS-1.0.7"
}
class func isInternetAvailable() -> Bool
{
var zeroAddress = sockaddr_in()
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()
if !SCNetworkReachabilityGetFlags(defaultRouteReachability!, &flags) {
return false
}
let isReachable = (flags.rawValue & UInt32(kSCNetworkFlagsReachable)) != 0
let needsConnection = (flags.rawValue & UInt32(kSCNetworkFlagsConnectionRequired)) != 0
return (isReachable && !needsConnection)
}
}