NSURLSession didCompleteWithError:调用NSError为nil [英] NSURLSession didCompleteWithError:gets called with NSError is nil

查看:1088
本文介绍了NSURLSession didCompleteWithError:调用NSError为nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当上传进行时,场景会将应用程序多次置于后台和前台,调用didCompleteWithError:方法,同时将app带到前台,其中error参数为null。 Probabilty是1/3。

Scenario is taking the app to background and foreground multiple times when its uploading is in progress,didCompleteWithError: method is called while taking app to foreground with error parameter is null. Probabilty is 1/3.

我如何找出错误,因为错误参数没有给出任何内容。

How do i find out what went wrong as error parameter does not give anything.

推荐答案

问题是didCompleteWithError报告客户端错误,否则为nil。 iOS doc说:

The problem is that didCompleteWithError report only client side error, otherwise is nil. iOS doc said:

服务器错误不会通过错误参数报告。
您的委托通过错误参数收到的唯一错误是客户端错误
,例如无法解析主机名或连接到主机。

这是链接到文档。

如果你想检查会话的错误,你必须实现会话协议委托

If you want to check session's errors you have to implement session protocol delegate

- URLSession:didBecomeInvalidWithError:

请记住在停止使用会话后使会话无效。
所以如果你创建这样的NSURLSession:

Remember to invalidate the session after stop using it. So if you create an NSURLSession like this:

NSURLSessionConfiguration *backgroundConfigurationObject = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"applycasession"];
    self.backgroundSession = [NSURLSession sessionWithConfiguration:backgroundConfigurationObject delegate:self delegateQueue:[NSOperationQueue mainQueue]];

当您使用完毕后,您必须致电:

When you finish to use it you have to call:

 [self.backgroundSession invalidateAndCancel];

请阅读有关 网址会话生命周期的文件在此链接

这篇关于NSURLSession didCompleteWithError:调用NSError为nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆