<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSExtensionContext/cancelRequest(withError:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSExtensionContext(im)cancelRequestWithError:"
  },
  "title" : "cancelRequest(withError:)"
}
-->

# cancelRequest(withError:)

Tells the host app to cancel the app extension request, with a supplied error.

```
func cancelRequest(withError error: any Error)
```

## Parameters

`error`

The error object to return. It must be non-`nil`.

## Discussion

On return, the `userInfo` dictionary of the [`NSError`](/documentation/Foundation/NSError) object contains a key named [`NSExtensionItemsAndErrorsKey`](/documentation/Foundation/NSExtensionItemsAndErrorsKey) which has as its value a dictionary of [`NSExtensionItem`](/documentation/Foundation/NSExtensionItem) objects and associated [`NSError`](/documentation/Foundation/NSError) instances.

## See Also

  [App Extension Programming Guide](https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/index.html#//apple_ref/doc/uid/TP40014214)



---

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)