我试图实现webservice调用,当用户截取屏幕截图时,我已经使用bellow方法成功实现了它。
con = pyodbc.connect('DSN=CHN')
csr = con.cursor()
csr.execute("SELECT * FROM DeviceLogs")
att_records = csr.fetchall()
但现在我有了这个场景,假设用户通过关闭互联网来获取屏幕截图,那么就不会发生webservice调用,用户将从中获益。现在我想要一些解决方案,如果没有可用的连接,我可以保存webservice呼叫,并在互联网连接可用时进行相同的呼叫。任何人都可以建议我如何进行此操作?
答案 0 :(得分:0)
使用Reachability检查互联网可用或不写下面的代码来检查互联网
//MARK:- check internet connection
func checkInternetStatus() {
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(reachabilityChanged(_:)), name:ReachabilityChangedNotification, object: nil)
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)) {
//Check for Internet Status
do {
self.reachability = try Reachability.reachabilityForInternetConnection()
try self.reachability?.startNotifier()
} catch {
jprint("Errore")
return
}
}
}
func reachabilityChanged(note:NSNotification) {
let Status = reachability?.currentReachabilityStatus //note.object as! Reachability
if Status != .NotReachable {
jprint("isNetworkAvailable = true")
isNetworkAvailable = true
} else {
jprint("isNetworkAvailable = false")
ShowFlinntAlert("No internet", description: "Your internet connection seems to be down")
isNetworkAvailable = false
}
}
在API调用之前,请检查
guard isInternetAvailable() else {
return
}