作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在使用 Ashley Mill 的 Reachability Class。如果应用程序通过网络连接启动,那么我可以在连接可用性之间切换而不会出现任何问题,并且能够正确显示网络连接警报 Controller 。但是,如果应用程序在没有互联网连接/飞行模式下启动时启动,它会突然崩溃。
override func viewDidLoad()
{
super.viewDidLoad()
setUpReachability (nil)
}
func setUpReachability(hostName: String?)
{
do
{
let reachability = try hostName == nil ? Reachability.reachabilityForInternetConnection() : Reachability(hostname: hostName!)
self.reachability = reachability
try! self.reachability?.startNotifier()
}
catch ReachabilityError.FailedToCreateWithAddress(let address)
{
print("\(address)")
return
} catch {}
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.reachabilityChanged(_:)), name: ReachabilityChangedNotification, object: reachability)
}
func reachabilityChanged(notification: NSNotification)
{
let reachability = notification.object as! Reachability
if reachability.isReachable()
{
if reachability.isReachableViaWiFi()
{
connected = true
}
else
{
connected = true
}
}
else
{
let alert = UIAlertController( title: "No Network Connection Available", message:"Try Again", preferredStyle: .Alert)
alert.addAction(UIAlertAction( title: "Will Do!" , style: .Default) { _ in } )
presentViewController ( alert, animated: true ) {}
connected = false
}
}
如何才能让 iPhone 应用程序启动并显示没有网络连接的警报而不是突然崩溃?
错误消息:
fatal error: unexpectedly found nil while unwrapping an Optional value
但我认为更改可达性会在 else 语句中捕获此内容并弹出错误消息?
最佳答案
reachability.isReachableViaWiFi() if 语句中的 else 不应该是:connected = false 吗?
关于ios - 应用程序在飞行模式下启动时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36510185/
在休眠状态挂接到我的JBoss AS 7.1之前,我试图在应用程序中运行flyway。我尝试使用@javax.ejb.Startup批注,但是在初始化Hibernate和检查数据库方案之后,此批注便会
我想将 div 移动到另一个 div 中。现在它们飞过整个页面。 我应该在代码中更改什么才能使其正常工作? $(document).ready(function() { $('.balloon')
我是一名优秀的程序员,十分优秀!