Error[8]: Undefined offset: 2, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述参见英文答案 > Check for internet connection with Swift                                    10个 有没有一个苹果框架包来检测是否有一个互联网连接?目前,当我的应用程序尝试在没有互联网连接的情况下对用户的位置进行地理位置分配 /*inside locationManager didUpdateLocations meth 参见英文答案 > Check for internet connection with Swift10个
有没有一个苹果框架包来检测是否有一个互联网连接?目前,当我的应用程序尝试在没有互联网连接的情况下对用户的位置进行地理位置分配
/*insIDe locationManager dIDUpdateLocations method*/var currentLocation:CLLocation? = locations[0] as? CLLocationgeocoder = CLGeocoder()//Crashes on line below when there isn't an internet connection//Need to add function to check if internet connection is live //Before running reverseGeocodeLocationgeocoder.reverseGeocodeLocation (currentLocation,handleGeocode)

我有点新的快速和ios编程 – 我的道歉.

解决方法 不是一个完整的网络检查库,但我发现了 this简单的方法来检查网络可用性.我设法把它翻译成Swift,并在这里是最终的代码.
import Foundationimport SystemConfigurationpublic class Reachability {    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))        zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress))        zeroAddress.sin_family = sa_family_t(AF_INET)        let defaultRouteReachability = withUnsafePointer(&zeroAddress) {            SCNetworkReachabilityCreateWithAddress(nil,UnsafePointer([+++])).takeRetainedValue()        }        var flags: SCNetworkReachabilityFlags = 0        if SCNetworkReachabilityGetFlags(defaultRouteReachability,&flags) == 0 {            return false        }        let isReachable = (flags & UInt32(kSCNetworkFlagsReachable)) != 0        let needsConnection = (flags & UInt32(kSCNetworkFlagsConnectionrequired)) != 0        return (isReachable && !needsConnection) ? true : false    }}

它适用于3G和WiFi连接.我也将其上传到我的Github一个工作的例子.如果您正在寻找一种简单的方法来检查纯粹在Swift中的网络可用性,您可以使用它.

总结

以上是内存溢出为你收集整理的ios – 检查互联网连接是否可用于swift全部内容,希望文章能够帮你解决ios – 检查互联网连接是否可用于swift所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
ios – 检查互联网连接是否可用于swift_app_内存溢出

ios – 检查互联网连接是否可用于swift

ios – 检查互联网连接是否可用于swift,第1张

概述参见英文答案 > Check for internet connection with Swift                                    10个 有没有一个苹果框架包来检测是否有一个互联网连接?目前,当我的应用程序尝试在没有互联网连接的情况下对用户的位置进行地理位置分配 /*inside locationManager didUpdateLocations meth 参见英文答案 > Check for internet connection with Swift10个
有没有一个苹果框架包来检测是否有一个互联网连接?目前,当我的应用程序尝试在没有互联网连接的情况下对用户的位置进行地理位置分配
/*insIDe locationManager dIDUpdateLocations method*/var currentLocation:CLLocation? = locations[0] as? CLLocationgeocoder = CLGeocoder()//Crashes on line below when there isn't an internet connection//Need to add function to check if internet connection is live //Before running reverseGeocodeLocationgeocoder.reverseGeocodeLocation (currentLocation,handleGeocode)

我有点新的快速和ios编程 – 我的道歉.

解决方法 不是一个完整的网络检查库,但我发现了 this简单的方法来检查网络可用性.我设法把它翻译成Swift,并在这里是最终的代码.
import Foundationimport SystemConfigurationpublic class Reachability {    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))        zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress))        zeroAddress.sin_family = sa_family_t(AF_INET)        let defaultRouteReachability = withUnsafePointer(&zeroAddress) {            SCNetworkReachabilityCreateWithAddress(nil,UnsafePointer()).takeRetainedValue()        }        var flags: SCNetworkReachabilityFlags = 0        if SCNetworkReachabilityGetFlags(defaultRouteReachability,&flags) == 0 {            return false        }        let isReachable = (flags & UInt32(kSCNetworkFlagsReachable)) != 0        let needsConnection = (flags & UInt32(kSCNetworkFlagsConnectionrequired)) != 0        return (isReachable && !needsConnection) ? true : false    }}

它适用于3G和WiFi连接.我也将其上传到我的Github一个工作的例子.如果您正在寻找一种简单的方法来检查纯粹在Swift中的网络可用性,您可以使用它.

总结

以上是内存溢出为你收集整理的ios – 检查互联网连接是否可用于swift全部内容,希望文章能够帮你解决ios – 检查互联网连接是否可用于swift所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1096492.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存