ios - nsurlsession ios 13 蜂窝错误域=NSURLErrorDomain 代码=-1009 "The Internet connection appears to be offline."

标签 ios nsurlsession ios13

    NSString *dataUrl = @"https://st2.depositphotos.com/2001755/5408/i/450/depositphotos_54081723-stock-photo-beautiful-nature-landscape.jpg";
    NSURL *url = [NSURL URLWithString:dataUrl];
    NSURLSessionConfiguration *configuration = NSURLSessionConfiguration.defaultSessionConfiguration;
    configuration.allowsCellularAccess = YES;
    configuration.waitsForConnectivity = YES;
    configuration.allowsExpensiveNetworkAccess = YES;
    configuration.allowsConstrainedNetworkAccess = YES;
    NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
    NSURLSessionDataTask *downloadTask = [session
      dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        NSLog(@"%@", error);
    }];
    [downloadTask resume];

我们有一个 2015 年开发的旧应用程序,它有很多旧代码。在 iOS 13 上,不幸的是在 CELLULAR 上所有 NSURLSession 请求(不仅对我们的服务器而且对任何服务器)都失败并出现错误:

Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={_kCFStreamErrorCodeKey=50, NSUnderlyingError=0x280526af0 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={NSURLErrorNetworkUnavailableReasonKey=1, kCFStreamErrorCodeKey=50, kCFStreamErrorDomainKey=1}}, NSURLErrorNetworkUnavailableReasonKey=1, NSLocalizedDescription=The Internet connection appears to be offline.

其中 NSURLErrorNetworkUnavailableReasonKey=1 是 URLError.NetworkUnavailableReason.expensive

NSURLConnection 请求没问题(弃用警告除外)

我应该打开什么全局设置,或者至少是本地设置,才能发出成功的请求?

最佳答案

经过 7 小时的调查,我发现问题出在库 CCInfiniteScrolling (github.com/ziryanov/CCInfiniteScrolling)。 NSObject 类别的问题和错误的运行时编码:NSObject+DProperty.m。我们将所有内容重写为 object_associations 并且一切正常。

关于ios - nsurlsession ios 13 蜂窝错误域=NSURLErrorDomain 代码=-1009 "The Internet connection appears to be offline.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58052982/

相关文章:

ios - 如何使用操作查询发出多个 Alamofire 请求

ios - 点击 UIButton 以编程方式创建另一个 UIButton

iphone - 从另一个 native iPhone 应用程序调用 native iPhone 应用程序的方法

ios - 在 backgroundfetch IOS 中时,第一个请求的下载任务为空

Swift REST 请求 PUT 可选(502 错误网关 : Registered endpoint failed to handle the request. )

ios - 如何同时支持 iOS 7 和 8 的 NSCalendar?

如果应用程序以 iPhone 横向启动,iOS 13 应用程序窗口会在 iPhone 上错误地旋转

swift - 如何在 SwiftUI 中添加自定义容器 View

iOS 13.0 触摸开始延迟较 iOS 12 有所增加

ios - NSURLSession 委托(delegate)队列中的死锁