---
title: "handleAppMessage(_:completionHandler:)"
framework: networkextension
role: symbol
role_heading: Instance Method
path: "networkextension/netunnelprovider/handleappmessage(_:completionhandler:)"
---

# handleAppMessage(_:completionHandler:)

Handle messages sent by the tunnel provider extension’s containing app.

## Declaration

```swift
func handleAppMessage(_ messageData: Data, completionHandler: (@Sendable (Data?) -> Void)? = nil)
```

```swift
func handleAppMessage(_ messageData: Data) async -> Data?
```

## Parameters

- `messageData`: The message data sent by the tunnel provider extension’s containing app.
- `completionHandler`: A block to be executed by the Tunnel Provider when it is finished handling the message. It may be nil, in which case the containing app does not expect a reply. The provider can send information back to the containing app via the responseData parameter.

## Discussion

Discussion Use this method to communicate information between the Tunnel Provider and the Tunnel Provider’s containing app. note: The Tunnel Provider’s containing app may not always be running at the same time as the Tunnel Provider extension. For example, the Tunnel Provider extension may have been started manually from the system’s network settings app or via Connect On Demand. Therefore, you should not rely on this communication channel with the containing app for basic Tunnel Provider operation (start, stop, etc.).
