---
title: "acceptConnectionInBackgroundAndNotify(forModes:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/filehandle/acceptconnectioninbackgroundandnotify(formodes:)"
---

# acceptConnectionInBackgroundAndNotify(forModes:)

Accepts a socket connection (for stream-type sockets only) in the background and creates a file handle for the “near” (client) end of the communications channel.

## Declaration

```swift
func acceptConnectionInBackgroundAndNotify(forModes modes: [RunLoop.Mode]?)
```

## Parameters

- `modes`: The runloop modes in which the connection accepted notification can be posted.

## Discussion

Discussion See acceptConnectionInBackgroundAndNotify() for details of how this method operates. This method differs from acceptConnectionInBackgroundAndNotify() in that modes specifies the run-loop mode (or modes) in which NSFileHandleConnectionAccepted can be posted. You must call this method from a thread that has an active run loop.

## See Also

### Related Documentation

- [enqueue(_:postingStyle:coalesceMask:forModes:)](foundation/notificationqueue/enqueue(_:postingstyle:coalescemask:formodes:).md)

### Reading asynchronously with notifications

- [acceptConnectionInBackgroundAndNotify()](foundation/filehandle/acceptconnectioninbackgroundandnotify().md)
- [readInBackgroundAndNotify()](foundation/filehandle/readinbackgroundandnotify().md)
- [readInBackgroundAndNotify(forModes:)](foundation/filehandle/readinbackgroundandnotify(formodes:).md)
- [readToEndOfFileInBackgroundAndNotify()](foundation/filehandle/readtoendoffileinbackgroundandnotify().md)
- [readToEndOfFileInBackgroundAndNotify(forModes:)](foundation/filehandle/readtoendoffileinbackgroundandnotify(formodes:).md)
- [waitForDataInBackgroundAndNotify()](foundation/filehandle/waitfordatainbackgroundandnotify().md)
- [waitForDataInBackgroundAndNotify(forModes:)](foundation/filehandle/waitfordatainbackgroundandnotify(formodes:).md)
