アクションを完了する前にUIButtonを押してインターネット接続をチェックすると、testReachability()メソッドが呼び出されます。これはAshley Millの到達可能クラスを使用しています。スウィフト - 到達可能でクラッシュする
On Line 24私はcomplete()メソッドを呼び出して、アプリケーションがネットワークに到達できる場合にはクロージャを完了し、残りの操作を続けるようにします。しかし、アプリケーションが異常になり、このエラーがデバッグコンソールに表示されます:
"このアプリケーションは、エンジンの破損や奇妙なクラッシュを引き起こす可能性のあるバックグラウンドスレッドから自動レイアウトエンジンを修正しています。 "
私がインターネット接続/飛行機モードに入るまで、アプリケーションは完全に素早く滑らかに実行されます。その後、アプリケーションは即座にクラッシュし、xcodeはデバイスのボタンをタップしてください。
私のアプリケーションのクラッシュを解決するには、到達可能性をチェックするために何ができますか。
func testReachability(completed: DownloadComplete)
{
let reachability: Reachability
do {
reachability = try Reachability.reachabilityForInternetConnection()
} catch {
return
}
reachability.whenReachable = { reachability in
// this is called on a background thread, but UI updates must
// be on the main thread, like this:
dispatch_async(dispatch_get_main_queue())
{
if reachability.isReachableViaWiFi()
{
print("Reachable via WiFi")
}
else
{
print("Reachable via Cellular")
}
}
completed()
}
reachability.whenUnreachable = { reachability in
// this is called on a background thread, but UI updates must
// be on the main thread, like this:
dispatch_async(dispatch_get_main_queue())
{
self.presentReachabilityAlertController()
}
}
do
{
try reachability.startNotifier()
}
catch
{
}
}
func presentReachabilityAlertController()
{
let alert = UIAlertController(title: "Network Connection Lost", message:"Try Again", preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "ok" , style: .Default) { _ in })
presentViewController (alert, animated: true ) { }
connected = false
}
コードに関連する部分をテキストではなく画像として質問に追加してください。 – JAL
http://stackoverflow.com/editing-helpを参照してください – jtbandes
@ JAL私の謝罪はすぐに固定 – lifewithelliott