gpt4 book ai didi

ios - 如何阻止用户,如果他/她在我的应用程序加载时未连接到互联网连接

转载 作者:行者123 更新时间:2023-11-28 08:42:40 25 4
gpt4 key购买 nike

我有一个应用程序,它是完整的 map View 。我需要的是如果用户未连接到互联网,我需要显示一些警报。我已经做到了。这是代码:

Reachability.swift.

import Foundation
import SystemConfiguration

public 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, 0, 0, 0, 0, 0, 0))
zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress))
zeroAddress.sin_family = sa_family_t(AF_INET)

let defaultRouteReachability = withUnsafePointer(&zeroAddress) {
SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, UnsafePointer($0))
}

var flags: SCNetworkReachabilityFlags = SCNetworkReachabilityFlags(rawValue: 0)
if SCNetworkReachabilityGetFlags(defaultRouteReachability!, &flags) == false {
return false
}

let isReachable = flags == .Reachable
let needsConnection = flags == .ConnectionRequired

return isReachable && !needsConnection

}
}
if Reachability.isConnectedToNetwork() == true {
println("Internet connection OK")
} else {
println("Internet connection FAILED")
var alert = UIAlertView(title: "No Internet Connection", message: "Make sure your device is connected to the internet.", delegate: nil, cancelButtonTitle: "OK")
alert.show()
}

但我需要的是:当用户未连接到互联网时,将显示一条 UIAlertView 消息。在该警报中,我有一个 OK 按钮。因此,在用户连接到互联网之前,可以将他们重定向到移动数据开/关设置,或者可以在用户连接到互联网之前显示 UIAlertView 消息..

请帮帮我!!

最佳答案

单击 alertview 中的确定按钮,您可以将用户重定向到所需页面,调用适当的 segue。第二个选项,如果你想阻止用户,只需显示带有自定义消息的事件指示器。

关于ios - 如何阻止用户,如果他/她在我的应用程序加载时未连接到互联网连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36081870/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com