NWPathMonitor : Lost connection to the debugger

I tried to monitor the device's network status with Network framework code below.

let networkMonitor = NWPathMonitor(requiredInterfaceType: .cellular)
networkMonitor.pathUpdateHandler = { [weak self] path in    
    if path.status == .satisfied {
        print("Cellular Satisfied")
    } else {
        print("Cellular Unsatisfied")
    }
}

When I run the app in my iPhone(iOS 15.5) and turn cellular on/off, iPhone suddenly loses connection with XCode.

Lost connection to the debugger on “...'s iPhone”.
Domain: IDEDebugSessionErrorDomain
Code: 12
Recovery Suggestion: Restore the connection to “...'s iPhone” and run “...” again, or if “...” is still running, you can attach to it by selecting Debug > Attach to Process > ....
User Info: {
    DVTErrorCreationDateKey = "2022-06-23 02:16:30 +0000";
    IDERunOperationFailingWorker = DBGLLDBLauncher;
}

Analytics Event: com.apple.dt.IDERunOperationWorkerFinished : {
    "device_model" = "iPhone13,2";
    "device_osBuild" = "15.5 (19F77)";
    "device_platform" = "com.apple.platform.iphoneos";
    "launchSession_schemeCommand" = Run;
    "launchSession_state" = 2;
    "launchSession_targetArch" = arm64;
    "operation_duration_ms" = 5861;
    "operation_errorCode" = 12;
    "operation_errorDomain" = IDEDebugSessionErrorDomain;
    "operation_errorWorker" = DBGLLDBLauncher;
    "operation_name" = IDEiPhoneRunOperationWorkerGroup;
    "param_consoleMode" = 0;
    "param_debugger_attachToExtensions" = 0;
    "param_debugger_attachToXPC" = 1;
    "param_debugger_type" = 5;
    "param_destination_isProxy" = 0;
    "param_destination_platform" = "com.apple.platform.iphoneos";
    "param_diag_MainThreadChecker_stopOnIssue" = 0;
    "param_diag_MallocStackLogging_enableDuringAttach" = 0;
    "param_diag_MallocStackLogging_enableForXPC" = 1;
    "param_diag_allowLocationSimulation" = 1;
    "param_diag_gpu_frameCapture_enable" = 0;
    "param_diag_gpu_shaderValidation_enable" = 0;
    "param_diag_gpu_validation_enable" = 0;
    "param_diag_memoryGraphOnResourceException" = 0;
    "param_diag_queueDebugging_enable" = 1;
    "param_diag_runtimeProfile_generate" = 0;
    "param_diag_sanitizer_asan_enable" = 0;
    "param_diag_sanitizer_tsan_enable" = 0;
    "param_diag_sanitizer_tsan_stopOnIssue" = 0;
    "param_diag_sanitizer_ubsan_stopOnIssue" = 0;
    "param_diag_showNonLocalizedStrings" = 0;
    "param_diag_viewDebugging_enabled" = 1;
    "param_diag_viewDebugging_insertDylibOnLaunch" = 1;
    "param_install_style" = 0;
    "param_launcher_UID" = 2;
    "param_launcher_allowDeviceSensorReplayData" = 0;
    "param_launcher_kind" = 0;
    "param_launcher_style" = 0;
    "param_launcher_substyle" = 0;
    "param_runnable_appExtensionHostRunMode" = 0;
    "param_runnable_productType" = "com.apple.product-type.application";
    "param_runnable_swiftVersion" = "5.6";
    "param_runnable_type" = 2;
    "param_testing_launchedForTesting" = 0;
    "param_testing_suppressSimulatorApp" = 0;
    "param_testing_usingCLI" = 0;
    "sdk_canonicalName" = "iphoneos15.4";
    "sdk_osVersion" = "15.4";
    "sdk_variant" = iphoneos;
}

In my opinion, it seems like an error of XCode. Plz let me know if there's any solution.

Also, there's a similar issue here : https://developer.apple.com/forums/thread/681459

Does this only happen when you’re running an NWPathMonitor? If you temporarily remove that code, do you still see the debugger disconnect like this?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

OMG the debugger still disconnects even though the NWPathMonitor was removed.

I think it's not a bug of XCode, not Network Framework 😂

debugger still disconnects even though the NWPathMonitor was removed

Interesting. I’ll re-tag your question then.

I tested this here in my office and I didn’t see this problem. Specifically:

  1. Using latest public Xcode, macOS, and iOS (13.4.1, 12.4, 15.5), I created a project from the iOS > App built-in template and ran it on my device.

  2. I then used Control Centre to toggle WWAN off and on.

  3. I saw no effect on my debugger connectivity.

Please repeat this test in your environment — specifically, test with a new project rather than your main app — and let us know what you see.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Facing same issue here. Can reproduce with empty project. (m1 Air silicon)

Can reproduce with empty project.

OK.

(m1 Air silicon)

But that’s not a lot of detail. What version of macOS? Of Xcode? Of iOS?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

NWPathMonitor : Lost connection to the debugger
 
 
Q