---
title: "stopTunnel(with:completionHandler:)"
framework: networkextension
role: symbol
role_heading: Instance Method
path: "networkextension/nepackettunnelprovider/stoptunnel(with:completionhandler:)"
---

# stopTunnel(with:completionHandler:)

Stop the network tunnel.

## Declaration

```swift
func stopTunnel(with reason: NEProviderStopReason, completionHandler: @escaping @Sendable () -> Void)
```

```swift
func stopTunnel(with reason: NEProviderStopReason) async
```

## Parameters

- `reason`: An NEProviderStopReason code indicating why the tunnel is being stopped. Possible codes are listed in doc://com.apple.networkextension/documentation/NetworkExtension/NEProvider.
- `completionHandler`: A block that must be executed when the tunnel is fully stopped.

## Discussion

Discussion This method is called by the system to stop the network tunnel. NEPacketTunnelProvider subclasses must override this method. Do not use this method to stop the tunnel from the Packet Tunnel Provider. Use cancelTunnelWithError: instead.

## See Also

### Managing the tunnel life cycle

- [startTunnel(options:completionHandler:)](networkextension/nepackettunnelprovider/starttunnel(options:completionhandler:).md)
- [cancelTunnelWithError(_:)](networkextension/nepackettunnelprovider/canceltunnelwitherror(_:).md)
