4

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

Performance - 2.1

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.

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.

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

    }
}

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

any help would be much appreciated!

Crash Log:

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
   
MattBlack
  • 3,616
  • 7
  • 32
  • 58
  • 4
    Apple should have sent you the crash log. Once symbolicated you will know the exact line of code causing the crash. No need to spend a day doing any research. And Apple did not say your app was rejected due to IPv6. It was rejected because it crashed. Use the crash log to know the actual cause. – rmaddy Sep 09 '16 at 20:23
  • Hi, I have added the crash log, if you could take a look that would be great :) – MattBlack Sep 10 '16 at 11:35
  • You need to post a symbolicated crash log. – rmaddy Sep 10 '16 at 14:53

2 Answers2

7

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. Don't use reachability to "preflight" before making connections. From Apple's guide to supporting modern networks:

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.

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. 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.

There's more good advice for supporting IPv6 and modern networks in the above links, and in WWDC16 session 714, "Networking for the Modern Internet".

Community
  • 1
  • 1
rickster
  • 124,678
  • 26
  • 272
  • 326
  • There is no evidence that IPv6 has anything to do with the OP's problem. Apple states the app crashes when the "more" button is tapped. The crash log needs to be viewed to learn the actual cause. – rmaddy Sep 09 '16 at 20:24
  • 1. The quoted rejection notice says the crash appears when pressing the "more" button *while connected to an IPv6-only network*. 2. As noted in the doc I quoted/linked, using Reachability to check connectivity with `0.0.0.0` is problematic on an IPv6 network, and that's exactly what @mattblack's code is doing. True, you could fix the *crash* through a more robust use of Reachability, but probably not the *rejection*, as it's still possible to do the wrong thing (and have broken functionality on an IPv6 network) without crashing. – rickster Sep 09 '16 at 20:31
  • @rickster: That was also my first thought, but according to https://developer.apple.com/library/ios/samplecode/Reachability/Listings/ReadMe_md.html: reachabilityForInternetConnection: "This monitors the address 0.0.0.0, which reachability treats as a special token that causes it to actually monitor the general routing status of the device, both IPv4 and IPv6." – But perhaps that does not work in an IPv6 *only* network, I cannot test it currently. – Martin R Sep 09 '16 at 20:34
  • Good catch, @MartinR — Apple's developer messaging seems to be inconsistent here, at least as to *how* to use Reachability. (That's worth [filing a bug](http://bugreport.apple.com).) However, the messaging is more clear on *when* to use Reachability: don't use it to preflight connections, which is what the OP seems to be doing. – rickster Sep 09 '16 at 20:40
  • @rickster: Sure. – On the other hand, the app may want to display a general "connected" status, independent of a target host. – Martin R Sep 09 '16 at 20:45
0

I got the same rejection reason a few days ago and after looking at some other questions/answers here, one of the answers solved this issue: updating every instance of AF_INET to AF_INET6 ... after this, my app passed and is available in the AppStore

Alan Gonzalez
  • 43
  • 1
  • 6