I have been stuck with this for a while and don\'t seem to get around this.
I am trying to read the contents of an URL as a string from an URL, But i get a weird
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.
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.
I got the same error, the above solution didn't work for me, in my case i was calling dataWithContentsOfURL from within a UNNotificationServiceExtension so i had to update the info.plist file of the UNNotificationServiceExtension with the app transport security entries.
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!
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.
More reasons that might be causing this specific error: