如果出现错误则停止查询(Parse.com)

时间:2014-12-01 20:06:52

标签: swift parse-platform

如果在运行查询时没有互联网连接,应用程序崩溃的那一刻。如果出现错误,如何告诉查询停止并阻止此操作? 感谢

以下错误:

Error: Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo=0x1702e0d80 {NSUnderlyingError=0x1742569e0 "The Internet connection appears to be offline.", NSErrorFailingURLStringKey=https://api.parse.com/2/find, NSErrorFailingURLKey=https://api.parse.com/2/find, _kCFStreamErrorDomainKey=12, _kCFStreamErrorCodeKey=8, NSLocalizedDescription=The Internet connection appears to be offline.} (Code: 100, Version: 1.2.21) 2014-12-01 20:36:39.257 AppName[5903:999805] Network connection failed. Making attempt 2 after sleeping for 1.546502 seconds.

1 个答案:

答案 0 :(得分:0)

在解析中,你可以处理很多事情的错误。

我认为如果没有互联网连接,您可以使用kPFErrorConnectionFailed

停止查询

实施例。

var query = PFQuery()
query.findObjectsInBackgroundWithBlock{
(success:Bool!, error:NSError!)-> Void in
                    if (error == nil) {

                      //continue query
                    }
                    else{

                        if(error.code == kPFErrorConnectionFailed) {
                            //handle error

                        }


                }     

        }