NSURLError错误码

本文详细列举并解释了iOS开发中常见的NSURLError错误码,包括网络连接失败、超时、无法解析URL等,帮助开发者解决网络请求过程中遇到的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<span style="font-family: Arial, Helvetica, sans-serif;">enum</span>
{
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorUnknown" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorUnknown</a> = -1,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorCancelled" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorCancelled</a> = -999,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorBadURL" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorBadURL</a> = -1000,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorTimedOut" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorTimedOut</a> = -1001,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorUnsupportedURL" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorUnsupportedURL</a> = -1002,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorCannotFindHost" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorCannotFindHost</a> = -1003,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorCannotConnectToHost" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorCannotConnectToHost</a> = -1004,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorDataLengthExceedsMaximum" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorDataLengthExceedsMaximum</a> = -1103,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorNetworkConnectionLost" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorNetworkConnectionLost</a> = -1005,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorDNSLookupFailed" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorDNSLookupFailed</a> = -1006,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorHTTPTooManyRedirects" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorHTTPTooManyRedirects</a> = -1007,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorResourceUnavailable" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorResourceUnavailable</a> = -1008,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorNotConnectedToInternet" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorNotConnectedToInternet</a> = -1009,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorRedirectToNonExistentLocation" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorRedirectToNonExistentLocation</a> = -1010,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorBadServerResponse" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorBadServerResponse</a> = -1011,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorUserCancelledAuthentication" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorUserCancelledAuthentication</a> = -1012,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorUserAuthenticationRequired" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorUserAuthenticationRequired</a> = -1013,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorZeroByteResource" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorZeroByteResource</a> = -1014,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorCannotDecodeRawData" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorCannotDecodeRawData</a> = -1015,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorCannotDecodeContentData" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorCannotDecodeContentData</a> = -1016,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorCannotParseResponse" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorCannotParseResponse</a> = -1017,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorInternationalRoamingOff" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorInternationalRoamingOff</a> = -1018,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorCallIsActive" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorCallIsActive</a> = -1019,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorDataNotAllowed" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorDataNotAllowed</a> = -1020,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorRequestBodyStreamExhausted" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorRequestBodyStreamExhausted</a> = -1021,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorFileDoesNotExist" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorFileDoesNotExist</a> = -1100,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorFileIsDirectory" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorFileIsDirectory</a> = -1101,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorNoPermissionsToReadFile" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorNoPermissionsToReadFile</a> = -1102,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorSecureConnectionFailed" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorSecureConnectionFailed</a> = -1200,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorServerCertificateHasBadDate" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorServerCertificateHasBadDate</a> = -1201,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorServerCertificateUntrusted" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorServerCertificateUntrusted</a> = -1202,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorServerCertificateHasUnknownRoot" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorServerCertificateHasUnknownRoot</a> = -1203,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorServerCertificateNotYetValid" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorServerCertificateNotYetValid</a> = -1204,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorClientCertificateRejected" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorClientCertificateRejected</a> = -1205,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorClientCertificateRequired" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorClientCertificateRequired</a> = -1206,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorCannotLoadFromNetwork" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorCannotLoadFromNetwork</a> = -2000,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorCannotCreateFile" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorCannotCreateFile</a> = -3000,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorCannotOpenFile" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorCannotOpenFile</a> = -3001,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorCannotCloseFile" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorCannotCloseFile</a> = -3002,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorCannotWriteToFile" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorCannotWriteToFile</a> = -3003,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorCannotRemoveFile" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorCannotRemoveFile</a> = -3004,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorCannotMoveFile" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorCannotMoveFile</a> = -3005,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorDownloadDecodingFailedMidStream" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorDownloadDecodingFailedMidStream</a> = -3006,
   <a target=_blank href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSURLErrorDownloadDecodingFailedToComplete" target="_blank" style="color: rgb(0, 51, 102); text-decoration: none;">NSURLErrorDownloadDecodingFailedToComplete</a> = -3007
}
<pre class="declaration" name="code" style="white-space: pre-wrap; word-wrap: break-word; font-size: 14px; line-height: 26px; background-color: rgb(255, 255, 255);"><a target=_blank href="https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html" target="_blank" style="color: rgb(255, 153, 0); text-decoration: none;">https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html</a>



                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值