我想提醒用戶,如果他們在我的xcode swift應用程序中沒有Internet連接,那麼我正在使用Reachablity來執行此操作。但是,當我實現我的代碼到的viewController我收到此錯誤:我在嘗試使用Reachablitiy時出現錯誤
Expected Declaration
我試圖把我的代碼爲viewdidload
,但也沒有奏效。
這是代碼:
if Reachability.checkIntenetRechable() == false {
let alertView = UIAlertCole: "APP_NAME", message: "Please check your internet connection.", preferredStyle: UIAlertControllerStyle.Alert)
//alertView.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: { (action: UIAlertAction) in }))
alertView.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction) in
// Put some code for okay button
}))
self.presentViewController(alertView, animated: true, completion: nil)
}
我們添加checkIntenetRechable在Reachability.swift文件()方法。 –
@ mr-bista看起來我們的編輯相互碰撞了,或者是你的錯誤。 :/(固定) – Moritz
你在可達性文件中添加了checkIntenetRechable()嗎?如果不是,請按照我的文章添加 –