NSURLErrorCancelled

NSURLErrorCancelled: Operation Canceled Error

Category: Platform-Specific Errors | Platforms: ios

What This Error Means

The NSURLErrorCancelled error signifies that an in-progress network request, or other asynchronous operation managed by NSURLSession, was explicitly canceled by the application or the system. This cancellation prevents the operation from completing successfully and returning data or an error.

Common Causes

  • User initiated cancellation (e.g., pressing a 'Cancel' button).
  • Application logic explicitly cancels the operation (e.g., navigating away from a view that initiated the request).
  • The NSURLSession object itself being invalidated (e.g., reset or closed).
  • Timeout errors leading to cancellation (though a different error code might be more appropriate in this case).
  • Low power mode initiating the cancellation of non-essential network requests.

How to Fix It (For Users)

  1. 1 If a download or upload was interrupted, restart it if possible.
  2. 2 Check your network connection to ensure stability.
  3. 3 If the problem persists, try closing and reopening the app.

For Site Owners / Developers

  1. Review the code to ensure cancellation is handled gracefully and does not lead to unexpected behavior.
  2. Implement proper error handling for `NSURLErrorCancelled` to distinguish it from other network errors.
  3. Avoid unnecessary cancellations of network requests. If a request is likely to be needed soon, consider caching the result instead of canceling.
  4. Consider using background tasks for long-running operations to prevent cancellation when the app is backgrounded.
  5. Examine the lifecycle of NSURLSession objects to ensure they are not being invalidated prematurely.

When It Is NOT Your Fault

This error can occur due to system-initiated events like low power mode engaging and canceling background network activity. It might also be caused by network instability outside of the user's control.

Is the website actually down?

Sometimes the issue is just on your end. Check if the website is down for everyone or just you.

Check Website Status →

Recommended Tool to Prevent This Error

Prevent server timeouts and resource exhaustion with scalable cloud infrastructure.

High-Performance Cloud Hosting