4 Replies
      Latest reply on Oct 8, 2018 1:54 AM by eskimo
      conan_the_librarian Level 1 Level 1 (0 points)

        I have some network code that has been reliable on several versions of iOS before iOS 12.  The code listed below fails with an EXC_BAD_ACCESS when called on device running iOS 12 when WIFI is turned off.  Has anyone else encountered this issue?  The code is based on code that Apple posted in one of the developer forums.  Here's a link to the reference code:

         

        https://forums.developer.apple.com/thread/11519

         

        - (NSData *)sendPostRequestImpl:(NSURLRequest *)request returningResponse:(NSURLResponse * __autoreleasing *)outResponse onError:(NSError * __autoreleasing *)outError

        {

            // Uses either NSURLConnection or NSURLSession depending on the iOS version detected

            NSData *responseData = nil;

            if ([self useNSURLConnection]) {

                responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:outResponse error:outError];

            } else {

                __block NSData *sessionResponseData = nil;

                __block dispatch_semaphore_t requestSemaphore;

         

                requestSemaphore = dispatch_semaphore_create(0);

         

                NSURLSessionDataTask *postRequestTask = [ _session dataTaskWithRequest:request completionHandler:^(NSData *data,

                                                                                                                  NSURLResponse *response,

                                                                                                                  NSError *error) {

                    if (error && outError) {

                        NSInteger errorCode = 13001;

                        *outError = [NSError errorWithDomain:error.domain code:errorCode userInfo:error.userInfo];

                    } else if ([response isKindOfClass:[NSHTTPURLResponse class]]) {

                        sessionResponseData = data;

                        if (response && outResponse) {

                            *outResponse = response;

                        }

                    }

                    dispatch_semaphore_signal(requestSemaphore);

         

                }];

         

                [postRequestTask resume];

                dispatch_semaphore_wait(requestSemaphore, DISPATCH_TIME_FOREVER);

                responseData = sessionResponseData;

            }

            return responseData;

        }

        • Re: Network code crashes when WIFI not available for IOS 12
          eskimo Apple Staff Apple Staff (12,305 points)

          It’s hard to say what’s going on here without seeing a crash report.  Please run it outside of Xcode, trigger the crash, grab the crash report, symbolicate it, and then post it here.

          Technote 2151 Understanding and Analyzing iOS Application Crash Reports has information about how to do this.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

            • Re: Network code crashes when WIFI not available for IOS 12
              conan_the_librarian Level 1 Level 1 (0 points)

                  I have a symbolicated crash report, but when I try to paste it here I see the error message "The message contains invalid characters".  I could paste a version with all the unicode characters stripped out, but that text is hard to read because all the end-of-line characters are removed.  Any suggestions?

              • Re: Network code crashes when WIFI not available for IOS 12
                conan_the_librarian Level 1 Level 1 (0 points)

                Thanks for helping with this.  The crash report can be found here.

                 

                https://pastebin.com/FjyRUrsg

                  • Re: Network code crashes when WIFI not available for IOS 12
                    eskimo Apple Staff Apple Staff (12,305 points)

                    The backtrace of your crashing thread looks like this:

                    Thread 3 Crashed:
                    0  libobjc.A.dylib         … objc_retain + 16
                    1  MobileXYZDebug          … 0x104624000 + 597064
                    2  MobileXYZDebug          … 0x104624000 + 373264
                    3  MobileXYZDebug          … 0x104624000 + 107632
                    4  libdispatch.dylib       … _dispatch_call_block_and_release + 32
                    5  libdispatch.dylib       … _dispatch_client_callout + 20
                    6  libdispatch.dylib       … _dispatch_continuation_pop + 408
                    7  libdispatch.dylib       … _dispatch_async_redirect_invoke + 596
                    8  libdispatch.dylib       … _dispatch_root_queue_drain + 348
                    9  libdispatch.dylib       … _dispatch_worker_thread2 + 120
                    10 libsystem_pthread.dylib … _pthread_wqthread + 476
                    11 libsystem_pthread.dylib … start_wqthread + 4

                    It’s hard to say exactly what’s going on here because frames 1 through 3 are not symbolicated.  However, a crash within objc_retain usually indicates a memory management problems, and in this case the code that did the retain is your app (frame 1) and thus it seems very likely that this is the result of a problem within your app.

                    I recommend that you symbolicate this log to see what object is being retained by frame 1.  You should also avail yourself of the standard memory debugging tools.

                    Share and Enjoy

                    Quinn “The Eskimo!”
                    Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                    let myEmail = "eskimo" + "1" + "@apple.com"