gpt4 book ai didi

ios - NSURLSession didCompleteWithError :gets called with NSError is nil

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:58:20 24 4
gpt4 key购买 nike

场景是在上传过程中多次将app调到后台和前台,调用didCompleteWithError:方法调到前台时error参数为null。概率是 1/3。

由于错误参数没有提供任何信息,我如何找出问题所在。

最佳答案

问题是 didCompleteWithError 报告 客户端错误,否则为零。 iOS 文档说:

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

这是 link到文档。

如果你想检查 session 的错误你必须实现 session 协议(protocol)委托(delegate)

- URLSession:didBecomeInvalidWithError:

记得在停止使用后使session失效。因此,如果您像这样创建一个 NSURLSession:

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

当你完成使用它时,你必须调用:

 [self.backgroundSession invalidateAndCancel];

请在此 link 阅读有关“URL session 生命周期”的文档

关于ios - NSURLSession didCompleteWithError :gets called with NSError is nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31262564/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com