GVKun编程网logo

swift – NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9802)(nsurlerror错误怎么办)

2

对于想了解swift–NSURLSession/NSURLConnectionHTTP加载失败(kCFStreamErrorDomainSSL,-9802)的读者,本文将是一篇不可错过的文章,我们将详

对于想了解swift – NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9802)的读者,本文将是一篇不可错过的文章,我们将详细介绍nsurlerror错误怎么办,并且为您提供关于(kCFStreamErrorDomainSSL, -9802) 错误解决、iOS 9中的HTTPS请求:NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9802)、iOS Swift - 崩溃:com.apple.NSURLSession-delegate EXC_BREAKPOINT 0x0000000102e35fc0、iOS Swift 应用程序随机 EXC_BAD_ACCESS 崩溃:swift_bridgeObjectRetain swift_retain swift::RefCounts的有价值信息。

本文目录一览:

swift – NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9802)(nsurlerror错误怎么办)

swift – NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9802)(nsurlerror错误怎么办)

我收到错误:NSURLSession / NSURLConnection HTTP加载失败(kcfStreamErrorDomainSSL,-9802),我怀疑这是因为查询来自Parse的图像.这是我查询的方法:
func fetchImageForEmployee(employee: PFEmployee,completion: (error: String?,image: UIImage?) -> Void) {
    if (employee.profilePicture == nil) {
        completion(error: "No image file",image: nil)
    } else {
        employee.profilePicture!.getDataInBackgroundWithBlock({ (data,error) -> Void in
            if let error = error {
                let errorString = error.userInfo["error"] as? String
                completion(error: errorString,image: nil)
            } else if (data != nil) {
                let image = UIImage(data: data!)
                completion(error: nil,image: image)
            } else {
                completion(error: nil,image: nil)
            }
        })
    }
}

我还打印了错误,这是调试器中出现的内容:不允许在取消分配时尝试加载视图控制器的视图,并且可能导致未定义的行为(UISearchController:0x13ee44dc0)

我不知道出了什么问题,所以所有答案都值得赞赏.

右键单击Info.plist文件>打开作为>源代码,并在最新的< / dict>之前添加以下内容:
<key>NSAppTransportSecurity</key>  
<dict>  
   <key>NSAllowsArbitraryLoads</key>  
   <true/>  
</dict>

在iOS9中,ATS在网络呼叫期间实施最佳实践,包括使用HTTPS.在Apple Documentation中了解更多相关信息.

(kCFStreamErrorDomainSSL, -9802) 错误解决

(kCFStreamErrorDomainSSL, -9802) 错误解决

只能再找方法试试了,找到了这个:修改 (...)/platforms/ios/嘎嚓嘎嚓/Classes/AppDelegate.m 文件,添加以下代码:

@implementation NSURLRequest(DataController) 
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host 
{ 
    return YES; 
} 
@end

哈哈。。。果然有用,简直 Nice!

不过,info.list 文件是之前修改过的,然后就觉得是不是只需要修改 AppDelegate.m 文件就可以呢?

经过验证是不行的,必须同时修改 info.list 和 AppDelegate.m 文件才可以解决此问题。

info.list 添加第一种代码即可:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key>
  <true/>
</dict>

iOS 9中的HTTPS请求:NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9802)

iOS 9中的HTTPS请求:NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9802)

我正在更新我的应用程序以适应苹果的新 ATS.没有对Plist-Info的任何更改,以下代码在vanilla iOS 9模拟器中的sendSynchronousRequest()中引发错误.
NSURL *url  =[NSURL URLWithString:@"https://Google.com"];
NSMutableuRLRequest *request = [[NSMutableuRLRequest alloc]init];
[request setHTTPMethod:@"GET"];
[request setURL:url];

NSURLResponse *urlResponse = nil;
NSError *error = nil;    
NSData *reponse = [NSURLConnection sendSynchronousRequest:request
                                        returningResponse:&urlResponse
                                                    error:&error];

错误:

NSURLSession / NSURLConnection HTTP加载失败(kcfStreamErrorDomainSSL,-9802)

对这个问题可能背后有什么想法?

Ps:据了解,NSURLConnection已被弃用.但是,如果我在Plist中添加了AllowArbitraryLoads,那么这个调用可以找到.

解决方法

NSURLSession / NSURLConnection HTTP加载失败(kcfStreamErrorDomainSSL,-9802)
对应于服务器不支持“Forward Secrecy”.

要解决此问题,请将域异常添加到.plist文件中,如下所示:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>test.testdomain.com</key>
    <dict>
      <key>NSIncludesSubdomains</key>
      <true/>
      <key>NstemporaryExceptionRequiresForwardSecrecy</key>
      <false/>
    </dict>

iOS Swift - 崩溃:com.apple.NSURLSession-delegate EXC_BREAKPOINT 0x0000000102e35fc0

iOS Swift - 崩溃:com.apple.NSURLSession-delegate EXC_BREAKPOINT 0x0000000102e35fc0

如何解决iOS Swift - 崩溃:com.apple.NSURLSession-delegate EXC_BREAKPOINT 0x0000000102e35fc0

我们的应用程序具有 pdf 和音频文件的下载功能。我在后台模式下添加了下载功能,但是应用程序有时会崩溃并且无法重现该步骤。这是 Firebase 崩溃报告。

Crashed: com.apple.NSURLSession-delegate
0  ios                  0x102e35fc0 specialized DownloadSessionDelegate.urlSession(_:dataTask:didReceive:completionHandler:) + 189 (<compiler-generated>:189)
1  ios                  0x102e32780 @objc DownloadSessionDelegate.urlSession(_:dataTask:didReceive:completionHandler:) + 4339345280 (<compiler-generated>:4339345280)
2  CFNetwork                      0x1810db158 _CFNetworkhttpconnectionCacheSetLimit + 155124
3  libdispatch.dylib              0x180573298 _dispatch_call_block_and_release + 24
4  libdispatch.dylib              0x180574280 _dispatch_client_callout + 16
5  libdispatch.dylib              0x18051cdcc _dispatch_lane_serial_drain$VARIANT$mp + 612
6  libdispatch.dylib              0x18051d8d8 _dispatch_lane_invoke$VARIANT$mp + 472
7  libdispatch.dylib              0x180527338 _dispatch_workloop_worker_thread + 712
8  libsystem_pthread.dylib        0x1c83bf5a4 _pthread_wqthread + 272
9  libsystem_pthread.dylib        0x1c83c2874 start_wqthread + 8

我在 AppDelegate.swift 中添加了后台会话处理程序。

    //MARK: background session handling
    func application(_ application: UIApplication,handleEventsForBackgroundURLSession identifier: String,completionHandler: @escaping () -> Void) {
        print("-- handleEventsForBackgroundURLSession --")
        let backgroundConfiguration = URLSessionConfiguration.background(withIdentifier: identifier)
        let backgroundSession = URLSession(configuration: backgroundConfiguration,delegate: DownloadSessionDelegate.sharedInstance,delegateQueue: nil)
        print("Rejoining session \\(backgroundSession)")
        
        DownloadSessionDelegate.sharedInstance.addCompletionHandler(completionHandler,identifier: identifier)
    }

这里是 DownloadSessionDelegate.swift 中的完成处理程序。我不确定是什么问题。

    //MARK: completion handler
    func addCompletionHandler(_ handler: @escaping CompleteHandlerBlock,identifier: String) {
        
        if identifier.isEmpty { return }
        
        dispatchQueue.global().async {
            self.handlerQueue[identifier] = handler
        }
        
    }

iOS Swift 应用程序随机 EXC_BAD_ACCESS 崩溃:swift_bridgeObjectRetain swift_retain swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1>

iOS Swift 应用程序随机 EXC_BAD_ACCESS 崩溃:swift_bridgeObjectRetain swift_retain swift::RefCounts

如何解决iOS Swift 应用程序随机 EXC_BAD_ACCESS 崩溃:swift_bridgeObjectRetain swift_retain swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1>

我不断收到来自随机用户的随机崩溃报告。不幸的是,我无法定期重现这一点。用户说崩溃是在 discussionViewController 中随机发生的。所有崩溃报告都有类似的内容:

0   libswiftCore.dylib              0x00000001a53face4 swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1> >::incrementSlow(swift::RefCountBitsT<(swift::RefCountInlinedness)1>,unsigned int) + 60 (atomic:1003)
1   libswiftCore.dylib              0x00000001a53c59e0 swift_retain + 124 (RefCount.h:813)
2   libswiftCore.dylib              0x00000001a5401d60 swift_bridgeObjectRetain + 56 (SwiftObject.mm:585)
3   APPNAME                             0x0000000102b59734 closure #1 in discussionViewController.fetchPostData() + 7916

这是完整的崩溃日志和崩溃的线程:

Hardware Model:      iphone11,6
Process:             APPNAME [11770]
Path:                /private/var/containers/Bundle/Application/.../APPNAME.app/APPNAME
Identifier:          ----
Version:             62 (62)
AppStoretools:       12E262
AppVariant:          1:iphone11,6:13
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           ---- [1824]


Date/Time:           2021-06-17 12:07:01.4346 +1000
Launch Time:         2021-06-17 12:06:56.4993 +1000
OS Version:          iPhone OS 14.6 (18F72)
Release Type:        User
Baseband Version:    3.04.01
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x8000000000000010 -> 0x0000000000000010 (possible pointer authentication failure)
VM Region Info: 0x10 is not in any region.  Bytes before following region: 4339515376
      REGION TYPE                 START - END      [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                   102a7c000-102a94000 [   96K] r-x/r-x SM=COW  ...APPNAME.app/APPNAME

Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL,Code 0xb
Terminating Process: exc handler [11770]
Triggered by Thread:  3


Thread 3 name:
Thread 3 Crashed:
0   libswiftCore.dylib              0x00000001a53face4 swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1> >::incrementSlow(swift::RefCountBitsT<(swift::RefCountInlinedness)1>,unsigned int) + 60 (atomic:1003)
1   libswiftCore.dylib              0x00000001a53c59e0 swift_retain + 124 (RefCount.h:813)
2   libswiftCore.dylib              0x00000001a5401d60 swift_bridgeObjectRetain + 56 (SwiftObject.mm:585)
3   APPNAME                             0x0000000102b59734 closure #1 in discussionViewController.fetchPostData() + 7916
4   APPNAME                             0x0000000102ad09d4 thunk for @escaping @callee_guaranteed (@guaranteed Data?,@guaranteed NSURLResponse?,@guaranteed Error?) -> () + 132 (<compiler-generated>:0)
5   CFNetwork                       0x00000001a1b0a3dc __40-[__NSURLSessionLocal taskForClassInfo:]_block_invoke + 540 (LocalSession.mm:687)
6   CFNetwork                       0x00000001a1b1c768 __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 244 (LocalSessionTask.mm:584)
7   libdispatch.dylib               0x00000001a10d1a84 _dispatch_call_block_and_release + 32 (init.c:1466)
8   libdispatch.dylib               0x00000001a10d381c _dispatch_client_callout + 20 (object.m:559)
9   libdispatch.dylib               0x00000001a10db004 _dispatch_lane_serial_drain + 620 (inline_internal.h:2557)
10  libdispatch.dylib               0x00000001a10dbc34 _dispatch_lane_invoke + 456 (queue.c:3862)
11  libdispatch.dylib               0x00000001a10e64bc _dispatch_workloop_worker_thread + 764 (queue.c:6589)
12  libsystem_pthread.dylib         0x00000001ed04a7a4 0x1ed047000 + 14244
13  libsystem_pthread.dylib         0x00000001ed05174c 0x1ed047000 + 42828

我已验证 discussionViewController.fetchPostData() 不会强制解开任何可选选项,没有 try! 并且在任何地方都使用 [weak self]self?。该函数非常大,所以我很难缩小崩溃发生的范围。

今天关于swift – NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9802)nsurlerror错误怎么办的介绍到此结束,谢谢您的阅读,有关(kCFStreamErrorDomainSSL, -9802) 错误解决、iOS 9中的HTTPS请求:NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9802)、iOS Swift - 崩溃:com.apple.NSURLSession-delegate EXC_BREAKPOINT 0x0000000102e35fc0、iOS Swift 应用程序随机 EXC_BAD_ACCESS 崩溃:swift_bridgeObjectRetain swift_retain swift::RefCounts等更多相关知识的信息可以在本站进行查询。

本文标签: