<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/FileHandle/acceptConnectionInBackgroundAndNotify(forModes:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileHandle(im)acceptConnectionInBackgroundAndNotifyForModes:"
  },
  "title" : "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.

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

## Parameters

`modes`

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

## Discussion

See [`acceptConnectionInBackgroundAndNotify()`](/documentation/Foundation/FileHandle/acceptConnectionInBackgroundAndNotify()) for details of how this method operates. This method differs from [`acceptConnectionInBackgroundAndNotify()`](/documentation/Foundation/FileHandle/acceptConnectionInBackgroundAndNotify()) in that `modes` specifies the run-loop mode (or modes) in which [`NSFileHandleConnectionAccepted`](/documentation/Foundation/NSNotification/Name-swift.struct/NSFileHandleConnectionAccepted) can be posted.

You must call this method from a thread that has an active run loop.

## See Also

[`enqueue(_:postingStyle:coalesceMask:forModes:)`](/documentation/Foundation/NotificationQueue/enqueue(_:postingStyle:coalesceMask:forModes:))

Adds a notification to the notification queue with a specified posting style, criteria for coalescing, and run loop mode.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)