NSCocoaErrorDomain Code=256

前端 未结 7 916
太阳男子
太阳男子 2020-12-01 20:59

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

相关标签:
7条回答
  • 2020-12-01 21:18

    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.

    0 讨论(0)
  • 2020-12-01 21:25

    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.

    0 讨论(0)
  • 2020-12-01 21:29

    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.

    0 讨论(0)
  • 2020-12-01 21:31

    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!

    0 讨论(0)
  • 2020-12-01 21:31

    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.

    0 讨论(0)
  • 2020-12-01 21:38

    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.
    0 讨论(0)
提交回复
热议问题