1
我有一个我正在处理的应用程序与Parse链接,所以我使用的是PFQueryTableViewController
。在Swift中检查与PFQueryTableViewController的互联网连接
我只想知道如何在运行应用程序时检查互联网连接。
目前,如果我关闭了我的互联网连接,然后运行应用程序,我得到表的加载微调,但显然,没有加载。最终,微调停下来,我只剩下一张空白的桌子。
我读过关于使用Reachability
,但不确定如何将它放入我目前的应用程序。
本质上,我想要的是,每次用户启动应用程序,它都会检查互联网连接,如果那样的话就很棒!如果没有,它会显示一条提示,表示无连接。
有人可以帮忙吗?我已经为queryForTable()
函数添加了我的代码,我认为这个检查应该发生。如果您需要查看我的其他代码,请告诉我。由于
override func queryForTable() -> PFQuery {
let query = PFQuery(className: "Reviews")
if indexArray == 0 {
query.orderByDescending("createdAt")
} else if indexArray == 1 {
query.orderByAscending("FilmName")
} else if indexArray == 2 {
query.orderByDescending("OurRating")
} else if indexArray == 3 {
query.orderByAscending("OurRating")
} else if indexArray == 4 {
query.orderByDescending("WantToSeeThisCount")
} else if indexArray == 5 {
query.orderByAscending("DirectedBy")
} else if indexArray == 6 {
query.orderByDescending("UpVoteCount")
} else if indexArray == 7 {
query.orderByDescending("DownVoteCount")
}
query.whereKey("ToDisplayInApp", equalTo:true)
// Add a where clause if there is a search criteria
if filmSearchBar.text != "" {
query.whereKey("FilmName", containsString: filmSearchBar.text!)
}
return query
}
这可以帮助你[可达](HTTP:/ /stackoverflow.com/a/34128493/3409505) –
我建议测试互联网是否可以访问,每当你想进行网络请求时,不仅仅是当用户打开应用程序时,可达性是最简单的解决方案,它不能简单的.. .. –