IPV6快速可达性 [英] IPV6 Swift Reachability

查看:61
本文介绍了IPV6快速可达性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Swift和Xcode&的新手.由于IPV6而拒绝了我的应用程序:

I am new to swift and xcode & have had my app rejected due to IPV6:

性能-2.1

Performance - 2.1

在以下情况下,您的应用程序在连接到IPv6网络的iPad和运行iOS 9.3.5的iPhone上崩溃:

Your app crashes on an iPad and an iPhone running iOS 9.3.5 connected >to an IPv6 network when we:

具体地说,当我们触摸应用程序右下角的更多"按钮时,它崩溃了.

Specifically, when we touch the More button in the bottom right hand corner of the app it crashed.

我花了很多时间阅读有关ipv6的内容,并得出结论,这可能是我正在使用的可达性课程.

I have spent a lot of the day doing reading around ipv6 and have concluded that it may be the reachability class I am using.

我有几个问题,如何修改代码以包含ipv6:

I have a couple of questions, how would I modify the code to include ipv6:

public class Reachability {

    class func isConnectedToNetwork() -> Bool {

        var zeroAddress = sockaddr_in(sin_len: 0, sin_family: 0, sin_port: 0, sin_addr: in_addr(s_addr: 0), sin_zero: (0, 0, 0, 0, 0, 0, 0, 0))
        zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress))
        zeroAddress.sin_family = sa_family_t(AF_INET)

        let defaultRouteReachability = withUnsafePointer(&zeroAddress) {
            SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, UnsafePointer($0))

        }

        var flags: SCNetworkReachabilityFlags = SCNetworkReachabilityFlags(rawValue: 0)
        if SCNetworkReachabilityGetFlags(defaultRouteReachability!, &flags) == false {
            return false
        }

        let isReachable = (flags.rawValue & UInt32(kSCNetworkFlagsReachable)) != 0
        let needsConnection = (flags.rawValue & UInt32(kSCNetworkFlagsConnectionRequired)) != 0        
        return isReachable && !needsConnection

    }
}

由于我使用的是http请求,我的服务器也必须配置为ipv6吗?

and because I am using http requests does my server have to be configured for ipv6 as well?

任何帮助将不胜感激!

崩溃日志:

Incident Identifier: C86A011D-2913-4FFE-992A-0E359781CECD
CrashReporter Key:   ae6778b695dfd22e7ce7236f09740cb14847b427
Hardware Model:      xxx
Process:             Fibre [3135]
Path:                /private/var/containers/Bundle/Application/8F9AF4E2-D64C-4C0C-8BF0-2C8FE63580EA/***
Identifier:          ***
Version:             1 (4.1.5)
Code Type:           ARM-64 (Native)
Parent Process:      launchd [1]

Date/Time:           2016-09-08 17:51:55.55 -0700
Launch Time:         2016-09-08 17:51:52.52 -0700
OS Version:          iOS 9.3.5 (13G36)
Report Version:      105

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000100032b54
Triggered by Thread:  5

Filtered syslog:
None found

Global Trace Buffer (reverse chronological seconds):
6148914686.196010 CFNetwork                 	0x0000000181b0a0a4 NSURLConnection finished with error - code -1003
6148914686.196214 CFNetwork                 	0x0000000181ad5d50 HTTP load failed (error code: -1003 [12:8])
6148914686.196214 CFNetwork                 	0x0000000181a596a8 _CFNetworkIsConnectedToInternet returning 1, flagsValid: 1, flags: 0x2
6148914686.196815 CFNetwork                 	0x0000000181abc184 TCP Conn 0x136fe5290 Failed : error 0:-65554 [-65554]
6148914686.196815 CFNetwork                 	0x0000000181abbe7c TCP Conn 0x136fe5290 complete. fd: -1, err: -65554
6148914686.196982 CFNetwork                 	0x0000000181abd3a8 TCP Conn 0x136fe5290 event 3. err: -65554
6148914686.198890 CFNetwork                 	0x0000000181abd480 TCP Conn 0x136fe5290 started
6148914686.200546 CFNetwork                 	0x0000000181b17e5c Creating default cookie storage with default identifier
6148914686.200546 CFNetwork                 	0x0000000181b17e28 Faulting in CFHTTPCookieStorage singleton
6148914686.200546 CFNetwork                 	0x0000000181b69e50 Faulting in NSHTTPCookieStorage singleton
6148914688.516532 AppleJPEG                 	0x0000000182e9626c [0x13808ee00] Created session



Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0:
0   libsystem_kernel.dylib        	0x0000000180fb4fd8 mach_msg_trap + 8
1   libsystem_kernel.dylib        	0x0000000180fb4e54 mach_msg + 72
2   CoreFoundation                	0x00000001813ecc60 __CFRunLoopServiceMachPort + 196
3   CoreFoundation                	0x00000001813ea964 __CFRunLoopRun + 1032
4   CoreFoundation                	0x0000000181314c50 CFRunLoopRunSpecific + 384
5   GraphicsServices              	0x0000000182bfc088 GSEventRunModal + 180
6   UIKit                         	0x00000001865fa088 UIApplicationMain + 204
7   Fibre                         	0x0000000100020b94 0x100004000 + 117652
8   libdyld.dylib                 	0x0000000180eb28b8 start + 4

Thread 1 name:  Dispatch queue: com.apple.NSURLSession-work
Thread 1:
0   libsystem_kernel.dylib        	0x0000000180fd14d8 kevent_qos + 8
1   libdispatch.dylib             	0x0000000180e944a8 _dispatch_kq_update + 152
2   libdispatch.dylib             	0x0000000180e94404 _dispatch_mgr_wakeup + 48
3   libdispatch.dylib             	0x0000000180e91a40 _dispatch_queue_wakeup_with_qos_slow + 40
4   libdispatch.dylib             	0x0000000180e8d694 _dispatch_queue_drain + 1332
5   libdispatch.dylib             	0x0000000180e84f80 _dispatch_queue_invoke + 464
6   libdispatch.dylib             	0x0000000180e8f390 _dispatch_root_queue_drain + 728
7   libdispatch.dylib             	0x0000000180e8f0b0 _dispatch_worker_thread3 + 112
8   libsystem_pthread.dylib       	0x0000000181099470 _pthread_wqthread + 1092
9   libsystem_pthread.dylib       	0x0000000181099020 start_wqthread + 4

Thread 2 name:  Dispatch queue: com.apple.libdispatch-manager
Thread 2:
0   libdispatch.dylib             	0x0000000180e96b84 _dispatch_source_kevent_unregister + 316
1   libdispatch.dylib             	0x0000000180e8390c _dispatch_source_invoke + 708
2   libdispatch.dylib             	0x0000000180e8390c _dispatch_source_invoke + 708
3   libdispatch.dylib             	0x0000000180e8d694 _dispatch_queue_drain + 1332
4   libdispatch.dylib             	0x0000000180e8dcd8 _dispatch_mgr_queue_drain + 44
5   libdispatch.dylib             	0x0000000180e94734 _dispatch_mgr_invoke + 68
6   libdispatch.dylib             	0x0000000180e83648 _dispatch_source_invoke + 0

Thread 3:
0   libsystem_kernel.dylib        	0x0000000180fd0b48 __workq_kernreturn + 8
1   libsystem_pthread.dylib       	0x0000000181099530 _pthread_wqthread + 1284
2   libsystem_pthread.dylib       	0x0000000181099020 start_wqthread + 4

Thread 4:
0   libsystem_kernel.dylib        	0x0000000180fd0b48 __workq_kernreturn + 8
1   libsystem_pthread.dylib       	0x0000000181099530 _pthread_wqthread + 1284
2   libsystem_pthread.dylib       	0x0000000181099020 start_wqthread + 4

Thread 5 name:  Dispatch queue: NSOperationQueue 0x136f35cc0 :: NSOperation 0x136fe3590 (QOS: LEGACY)
Thread 5 Crashed:
0   Fibre                         	0x0000000100032b54 0x100004000 + 191316
1   CFNetwork                     	0x0000000181a965ac __67+[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]_block_invoke_2 + 180
2   Foundation                    	0x0000000181df0540 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 16
3   Foundation                    	0x0000000181d42870 -[NSBlockOperation main] + 96
4   Foundation                    	0x0000000181d32e48 -[__NSOperationInternal _start:] + 604
5   Foundation                    	0x0000000181df2934 __NSOQSchedule_f + 224
6   libdispatch.dylib             	0x0000000180e8147c _dispatch_client_callout + 16
7   libdispatch.dylib             	0x0000000180e8d4c0 _dispatch_queue_drain + 864
8   libdispatch.dylib             	0x0000000180e84f80 _dispatch_queue_invoke + 464
9   libdispatch.dylib             	0x0000000180e8f390 _dispatch_root_queue_drain + 728
10  libdispatch.dylib             	0x0000000180e8f0b0 _dispatch_worker_thread3 + 112
11  libsystem_pthread.dylib       	0x0000000181099470 _pthread_wqthread + 1092
12  libsystem_pthread.dylib       	0x0000000181099020 start_wqthread + 4

Thread 6:
0   libsystem_kernel.dylib        	0x0000000180fd0b48 __workq_kernreturn + 8
1   libsystem_pthread.dylib       	0x0000000181099530 _pthread_wqthread + 1284
2   libsystem_pthread.dylib       	0x0000000181099020 start_wqthread + 4

Thread 7:
0   libsystem_kernel.dylib        	0x0000000180fd0b48 __workq_kernreturn + 8
1   libsystem_pthread.dylib       	0x0000000181099530 _pthread_wqthread + 1284
2   libsystem_pthread.dylib       	0x0000000181099020 start_wqthread + 4

Thread 8:
0   libsystem_kernel.dylib        	0x0000000180fd0b48 __workq_kernreturn + 8
1   libsystem_pthread.dylib       	0x0000000181099530 _pthread_wqthread + 1284
2   libsystem_pthread.dylib       	0x0000000181099020 start_wqthread + 4

Thread 9 name:  com.apple.NSURLConnectionLoader
Thread 9:
0   libsystem_kernel.dylib        	0x0000000180fb4fd8 mach_msg_trap + 8
1   libsystem_kernel.dylib        	0x0000000180fb4e54 mach_msg + 72
2   CoreFoundation                	0x00000001813ecc60 __CFRunLoopServiceMachPort + 196
3   CoreFoundation                	0x00000001813ea964 __CFRunLoopRun + 1032
4   CoreFoundation                	0x0000000181314c50 CFRunLoopRunSpecific + 384
5   CFNetwork                     	0x0000000181a95bcc +[NSURLConnection(Loader) _resourceLoadLoop:] + 412
6   Foundation                    	0x0000000181e0be4c __NSThread__start__ + 1000
7   libsystem_pthread.dylib       	0x000000018109bb28 _pthread_body + 156
8   libsystem_pthread.dylib       	0x000000018109ba8c _pthread_body + 0
9   libsystem_pthread.dylib       	0x0000000181099028 thread_start + 4

Thread 5 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000000   x1: 0x0000000000000000   x2: 0x0000000136db3890   x3: 0x0000000136f6dda0
    x4: 0x0000000100039250   x5: 0x0000000000000001   x6: 0x0000000000000000   x7: 0x0000000000000a30
    x8: 0x0000000136fd58f8   x9: 0x0000000000000004  x10: 0x0000000000000000  x11: 0x0000000000000000
   x12: 0x0000000137091190  x13: 0x000005a1001e9247  x14: 0x00000000ffffffff  x15: 0x00000000ffffffff
   x16: 0x00000001003ec47c  x17: 0x0000000186e3db68  x18: 0x0000000000000000  x19: 0x0000000000000000
   x20: 0x0000000136db3890  x21: 0x0000000000000000  x22: 0x0000000136fe5b50  x23: 0x0000000136f6dda0
   x24: 0x8e00a063ef134017  x25: 0x00000000000000d8  x26: 0x0000000000020001  x27: 0x00000000240008ff
   x28: 0x0000000000010001  fp: 0x000000016e246a00   lr: 0x0000000181a965ac
    sp: 0x000000016e246980   pc: 0x0000000100032b54 cpsr: 0x20000000

Binary Images:
0x100004000 - 0x100193fff Fibre arm64  <a3baaae1e0f93363a87211e3e15a394e> /var/containers/Bundle/Application/8F9AF4E2-D64C-4C0C-8BF0-2C8FE63580EA/Fibre.app/Fibre
0x10021c000 - 0x10041bfff libswiftCore.dylib arm64  <39ceee8206bb32809dab8ecba2e05d8e> /var/containers/Bundle/Application/8F9AF4E2-D64C-4C0C-8BF0-2C8FE63580EA/Fibre.app/Frameworks/libswiftCore.dylib
   

推荐答案

从拒绝通知中可以看出,您的问题来自于仅在IPv6和其他现代网络拓扑上不再有效的假设.这里有两个步骤可以继续前进...

As seen in the rejection notice, your problems stem from assumptions that are no longer valid on IPv6-only and other modern network topologies. There's two steps to move forward here...

  1. 请勿使用可达性来预检"在建立连接之前.从Apple的
  1. Don't use reachability to "preflight" before making connections. From Apple's guide to supporting modern networks:

可达性API(请参阅 SCNetworkReachability参考)用于诊断目的之后确定连接问题.许多应用程序错误地使用这些API来调用 SCNetworkReachabilityCreateWithAddress 方法,并将其传递给0.0.0.0的IPv4地址,该地址表示网络上存在路由器.但是,路由器的存在并不能保证存在互联网连接.通常,避免预检网络可达性.只需尝试建立连接并妥善处理故障即可.如果必须检查网络可用性,请避免调用 SCNetworkReachabilityCreateWithAddress 方法.调用 SCNetworkReachabilityCreateWithName 方法,并将其传递为主机名.

The Reachability APIs (see SCNetworkReachability Reference) are intended for diagnostic purposes after identifying a connectivity issue. Many apps incorrectly use these APIs to proactively check for an Internet connection by calling the SCNetworkReachabilityCreateWithAddress method and passing it an IPv4 address of 0.0.0.0, which indicates that there is a router on the network. However, the presence of a router doesn’t guarantee that an Internet connection exists. In general, avoid preflighting network reachability. Just try to make a connection and gracefully handle failures. If you must check for network availability, avoid calling the SCNetworkReachabilityCreateWithAddress method. Call the SCNetworkReachabilityCreateWithName method and pass it a hostname instead.

某些应用还通过 SCNetworkReachabilityCreateWithAddress 方法将IPv4地址设置为169.254.0.0,这是一个自行分配的本地链接地址,用于检查有效的Wi-Fi连接.要检查Wi-Fi或蜂窝连接性,请查找网络可达性标志 kSCNetworkReachabilityFlagsIsWWAN 代替.

Some apps also pass the SCNetworkReachabilityCreateWithAddress method an IPv4 address of 169.254.0.0, a self-assigned link-local address, to check for an active Wi-Fi connection. To check for Wi-Fi or cellular connectivity, look for the network reachability flag kSCNetworkReachabilityFlagsIsWWAN instead.

  1. 使用仅IPv6的网络进行测试,然后再提交到App Store.您可以
  1. Test with IPv6-only networks before submitting to the App store. You can set up a NAT64 gateway on your development Mac to create an IPv6-only network for use by your test devices.

在上述链接以及 WWDC16会议714,现代互联网的联网" .

这篇关于IPV6快速可达性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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