gpt4 book ai didi

ios - 手机处于飞行模式时如何检测 iCloud 用户?

转载 作者:行者123 更新时间:2023-11-30 13:04:12 25 4
gpt4 key购买 nike

首先我知道这篇文章:How to identify iCloud logged in user in airplane mode?

但似乎没有答案。一个答案涉及检测互联网连接,另一个答案涉及用户是否已更改。

这是我的代码:

container.accountStatusWithCompletionHandler{
(status: CKAccountStatus, error: NSError?) in

dispatch_async(dispatch_get_main_queue(), {

var title: String!
var message: String!

if error != nil{
title = "Error"
message = "An error occurred = \(error)"
} else {
//title = "No errors occurred getting info"
switch status{
case .Available:
message = "The user is logged in to iCloud"
title = "GOOD"
print("determined status was available")
self.shouldPullFromICloud()
//self.displayAlertWithTitle(title, message: message)
case .CouldNotDetermine:
message = "Could not determine if the user is logged" +
" into iCloud or not"
title = "BAD"
self.noUserIsSignedIn()
case .NoAccount:
message = "User is not logged into iCloud"
title = "BAD"
self.noUserIsSignedIn()
case .Restricted:
message = "Could not access user's iCloud account information"
title = "BAD"
self.noUserIsSignedIn()
}
print(title, message)
}
})
}

您需要互联网连接才能查看用户是否登录 iCloud,这似乎很愚蠢。我该如何解决这个问题?

谢谢!

附注如果其他帖子确实包含了我的问题的答案,您可以帮我突出显示吗?我找不到它。干杯!

最佳答案

飞行模式只是关闭蜂窝和 WiFi 数据功能。在这种情况下,检查可达性应与检测飞行模式具有相同的目的。这是一个标准的库片段,用于检查可达性:

func connectedToNetwork() -> Bool {
var zeroAddress = sockaddr_in()
zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress))
zeroAddress.sin_family = sa_family_t(AF_INET)

guard let defaultRouteReachability = withUnsafePointer(&zeroAddress, {
SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0))
}) else {
return false
}
var flags : SCNetworkReachabilityFlags = []

if SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags) == false {
return false
}

let isReachable = flags.contains(.Reachable)
let needsConnection = flags.contains(.ConnectionRequired)
return (isReachable && !needsConnection)
}

关于ios - 手机处于飞行模式时如何检测 iCloud 用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39574201/

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