<!--
{
  "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/readInBackgroundAndNotify()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileHandle(im)readInBackgroundAndNotify"
  },
  "title" : "readInBackgroundAndNotify()"
}
-->

# readInBackgroundAndNotify()

Reads from the file or communications channel in the background and posts a notification when finished.

```
func readInBackgroundAndNotify()
```

## Discussion

This method performs an asynchronous [`availableData`](/documentation/Foundation/FileHandle/availableData) operation on a file or communications channel and posts an [`readCompletionNotification`](/documentation/Foundation/FileHandle/readCompletionNotification) notification on the current thread when that operation is complete. You must call this method from a thread that has an active run loop.

The length of the data is limited to the buffer size of the underlying operating system. The notification includes a `userInfo` dictionary that contains the data read; access this object using the `NSFileHandleNotificationDataItem` key.

Any object interested in receiving this data asynchronously must add itself as an observer of [`readCompletionNotification`](/documentation/Foundation/FileHandle/readCompletionNotification). In communication via stream-type sockets, the receiver is often the object returned in the `userInfo` dictionary of [`NSFileHandleConnectionAccepted`](/documentation/Foundation/NSNotification/Name-swift.struct/NSFileHandleConnectionAccepted).

Note that this method does not cause a continuous stream of notifications to be sent. If you wish to keep getting notified, you’ll also need to call [`readInBackgroundAndNotify()`](/documentation/Foundation/FileHandle/readInBackgroundAndNotify()) in your observer method.

## See Also

[`-  enqueueNotification: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)