Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对方法“[NSStrng stringWithContentOfURL:url]”有疑问;一切都很好,直到我将我的网址从一个网址更改为一个我得到一个空字符串的 IP 地址。你有解决方案或想法吗?谢谢
使用返回错误状态的方法(例如+stringWithContentsOfURL:encoding:error:)并检查错误返回。
+stringWithContentsOfURL:encoding:error:
更新:NSCocoaErrorDomain Code=256 是“NSFileReadUnknownError”,意思是“文件读取错误,原因未知”(不是很有帮助)。URL 可能有问题(路径名拼写错误、IP 地址错误等)
URL 绝对支持数字 IP 地址,所以这不是问题。
另请参阅iPhone - dataWithContentsOfURL: 不适用于某些 URL