NSCocoaErrorDomain Code=256

Solution 1:

Yes, the URL is missing the scheme: "http://".

"Error -> Error Domain=NSCocoaErrorDomain Code=256"

For the error code check the Apple documentation:

NSError codes in the Cocoa error domain.

NSFileReadUnknownError = 256,

NSFileReadUnknownError
"Read error, reason unknown"

Not that the error definition is very helpful. :-)

Also do not check if error is nil to determine if there is an error, check the return value for nil. error is not guaranteed to be nil on successful execution.

Solution 2:

I had a similar problem accessing files located on my device. I followed NSURL isFileURL always returns NO and used [NSURL fileURLWithPath] instead of [NSURL URLWithString] - this worked!

Solution 3:

I got this error (Error Domain=NSCocoaErrorDomain Code=256) as soon as our ssl certificate expired. that may not help you but could help someone else.

Solution 4:

Sandboxing

If you're using sandboxing in your app, you might want to check that com.apple.security.network.client is set to YES. It's in the the General tab of your Target in Xcode 5 under

Network: Outgoing Connections (Client)

Also be aware that if you see a code 257 when trying to reach a file:/// url, that's also probably because of sandboxing, but this time rather the File Access part. Because I didn't want to open it to anything else than `com.apple.security.files.user-selected.read-write'

User selected files

I preferred to use A Dead Simple Fileserver and use http://localhost:3000 when in Debug mode.

Solution 5:

More reasons that might be causing this specific error:

  1. SSL is misconfigured on the server
  2. The server redirects (301) the http URL to https (see #1)
  3. App transport security also uses this code for blocked requests.