ios 未记录的 NSURLErrorDomain 错误代码(-1001、-1003 和 -1004)使用 StoreKit
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6778167/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Undocumented NSURLErrorDomain error codes (-1001, -1003 and -1004) using StoreKit
提问by Hyperbole
I'm writing StoreKit-related code, and I'm getting some rather troubling error codes when I try to add a purchase to the queue.
我正在编写与 StoreKit 相关的代码,当我尝试将购买添加到队列时,我收到了一些相当令人不安的错误代码。
So far, I've experienced error codes -1003 and -1004 and I can't find anything about those codes on the internet.
到目前为止,我遇到了错误代码 -1003 和 -1004,但我在互联网上找不到关于这些代码的任何信息。
Running a product request returns valid product numbers, so I don't know why calls to [[SKPaymentQueue defaultQueue] addPayment:aPayment];
would fail with this undocumented problem.
运行产品请求会返回有效的产品编号,所以我不知道为什么调用[[SKPaymentQueue defaultQueue] addPayment:aPayment];
会因这个未记录的问题而失败。
The same code also works without the errors on one device but not on another.
相同的代码在一台设备上也没有错误,但在另一台设备上却没有。
The questions I have are, as of yet, unanswered:
到目前为止,我的问题尚未得到解答:
What do these codes mean? How can I mitigate this problem? Why are they happening for purchase attempts and not for product requests?
这些代码是什么意思?我该如何缓解这个问题?为什么它们发生在购买尝试而不是产品请求中?
Troubleshooting I've done includes regenerating a signing certificate and provisioning profile, changing WiFi networks, cleaning and building and reinstalling all related software and components, and none of these things individually or together have helped fix the problem.
我所做的故障排除包括重新生成签名证书和配置文件、更改 WiFi 网络、清理和构建并重新安装所有相关的软件和组件,这些单独或一起使用都没有帮助解决问题。
EDIT:
编辑:
Found a discussion about this on the Apple dev forums, but no one from Apple has responded: https://devforums.apple.com/thread/107121?tstart=75(iOS developer account required to view)
在苹果开发者论坛上找到了关于这个的讨论,但苹果没有人回应:https: //devforums.apple.com/thread/107121?tstart =75(需要iOS开发者账号查看)
EDIT:
编辑:
I was hit with error code -1001 today, to add to this list of inexplicable and intermittent problems. Still no accountability from Apple, that I can find.
我今天遇到了错误代码 -1001,添加到这个莫名其妙和间歇性问题的列表中。仍然没有来自 Apple 的责任,我可以找到。
EDIT:
编辑:
I have a suspicion that these error codes are randomly generated and really only indicate that the Sandbox is down. Anyone else experience this problem?
我怀疑这些错误代码是随机生成的,实际上仅表明沙箱已关闭。还有其他人遇到过这个问题吗?
回答by martinezdelariva
All error codes are on "CFNetwork Errors Codes References" on the documentation (link)
所有错误代码都在文档(链接)的“CFNetwork 错误代码参考”中
A small extraction for CFURL and CFURLConnection Errors:
CFURL 和 CFURLConnection 错误的小提取:
kCFURLErrorUnknown = -998,
kCFURLErrorCancelled = -999,
kCFURLErrorBadURL = -1000,
kCFURLErrorTimedOut = -1001,
kCFURLErrorUnsupportedURL = -1002,
kCFURLErrorCannotFindHost = -1003,
kCFURLErrorCannotConnectToHost = -1004,
kCFURLErrorNetworkConnectionLost = -1005,
kCFURLErrorDNSLookupFailed = -1006,
kCFURLErrorHTTPTooManyRedirects = -1007,
kCFURLErrorResourceUnavailable = -1008,
kCFURLErrorNotConnectedToInternet = -1009,
kCFURLErrorRedirectToNonExistentLocation = -1010,
kCFURLErrorBadServerResponse = -1011,
kCFURLErrorUserCancelledAuthentication = -1012,
kCFURLErrorUserAuthenticationRequired = -1013,
kCFURLErrorZeroByteResource = -1014,
kCFURLErrorCannotDecodeRawData = -1015,
kCFURLErrorCannotDecodeContentData = -1016,
kCFURLErrorCannotParseResponse = -1017,
kCFURLErrorInternationalRoamingOff = -1018,
kCFURLErrorCallIsActive = -1019,
kCFURLErrorDataNotAllowed = -1020,
kCFURLErrorRequestBodyStreamExhausted = -1021,
kCFURLErrorFileDoesNotExist = -1100,
kCFURLErrorFileIsDirectory = -1101,
kCFURLErrorNoPermissionsToReadFile = -1102,
kCFURLErrorDataLengthExceedsMaximum = -1103,
回答by JOM
I have similar problems, in my case seem to be related to network connectivity:
我有类似的问题,就我而言,似乎与网络连接有关:
Error Domain=NSURLErrorDomain Code=-1001 "The request timed out."
错误域=NSURLErrorDomain 代码=-1001 “请求超时。”
Things to check:
检查事项:
- Is there any chance that your server is not able to respond within some time limit? Like 60 seconds or 4 minutes?
- Is there a possibility that your device is switching networks (WiFi, 3G, VPN)?
- Could someone (client vs. server) be waiting for authentication?
- 您的服务器是否有可能在一定时间内无法响应?像 60 秒还是 4 分钟?
- 您的设备是否有可能正在切换网络(WiFi、3G、VPN)?
- 是否有人(客户端与服务器)正在等待身份验证?
Sorry, no ideas how to fix. Just debugging this, trying to find out what the problem is (-1021, -1001, -1009)
抱歉,不知道如何解决。只是调试这个,试图找出问题所在(-1021,-1001,-1009)
Update:Google search was very kind to find this:
更新:谷歌搜索很高兴找到这个:
- -1001 TimedOut - it took longer than the timeout which was alotted.
- -1003 CannotFindHost - the host could not be found.
- -1004 CannotConnectToHost - the host would not let us establish a connection.
- -1001 TimedOut - 花费的时间比分配的超时时间长。
- -1003 CannotFindHost - 找不到主机。
- -1004 CannotConnectToHost - 主机不会让我们建立连接。
回答by Acorld
see NSURLError.h Define
见 NSURLError.h 定义
NSURLErrorUnknown = -1,
NSURLErrorCancelled = -999,
NSURLErrorBadURL = -1000,
NSURLErrorTimedOut = -1001,
NSURLErrorUnsupportedURL = -1002,
NSURLErrorCannotFindHost = -1003,
NSURLErrorCannotConnectToHost = -1004,
NSURLErrorNetworkConnectionLost = -1005,
NSURLErrorDNSLookupFailed = -1006,
NSURLErrorHTTPTooManyRedirects = -1007,
NSURLErrorResourceUnavailable = -1008,
NSURLErrorNotConnectedToInternet = -1009,
NSURLErrorRedirectToNonExistentLocation = -1010,
NSURLErrorBadServerResponse = -1011,
NSURLErrorUserCancelledAuthentication = -1012,
NSURLErrorUserAuthenticationRequired = -1013,
NSURLErrorZeroByteResource = -1014,
NSURLErrorCannotDecodeRawData = -1015,
NSURLErrorCannotDecodeContentData = -1016,
NSURLErrorCannotParseResponse = -1017,
NSURLErrorAppTransportSecurityRequiresSecureConnection NS_ENUM_AVAILABLE(10_11, 9_0) = -1022,
NSURLErrorFileDoesNotExist = -1100,
NSURLErrorFileIsDirectory = -1101,
NSURLErrorNoPermissionsToReadFile = -1102,
NSURLErrorDataLengthExceedsMaximum NS_ENUM_AVAILABLE(10_5, 2_0) = -1103,
// SSL errors
NSURLErrorSecureConnectionFailed = -1200,
NSURLErrorServerCertificateHasBadDate = -1201,
NSURLErrorServerCertificateUntrusted = -1202,
NSURLErrorServerCertificateHasUnknownRoot = -1203,
NSURLErrorServerCertificateNotYetValid = -1204,
NSURLErrorClientCertificateRejected = -1205,
NSURLErrorClientCertificateRequired = -1206,
NSURLErrorCannotLoadFromNetwork = -2000,
// Download and file I/O errors
NSURLErrorCannotCreateFile = -3000,
NSURLErrorCannotOpenFile = -3001,
NSURLErrorCannotCloseFile = -3002,
NSURLErrorCannotWriteToFile = -3003,
NSURLErrorCannotRemoveFile = -3004,
NSURLErrorCannotMoveFile = -3005,
NSURLErrorDownloadDecodingFailedMidStream = -3006,
NSURLErrorDownloadDecodingFailedToComplete =-3007,
NSURLErrorInternationalRoamingOff NS_ENUM_AVAILABLE(10_7, 3_0) = -1018,
NSURLErrorCallIsActive NS_ENUM_AVAILABLE(10_7, 3_0) = -1019,
NSURLErrorDataNotAllowed NS_ENUM_AVAILABLE(10_7, 3_0) = -1020,
NSURLErrorRequestBodyStreamExhausted NS_ENUM_AVAILABLE(10_7, 3_0) = -1021,
NSURLErrorBackgroundSessionRequiresSharedContainer NS_ENUM_AVAILABLE(10_10, 8_0) = -995,
NSURLErrorBackgroundSessionInUseByAnotherProcess NS_ENUM_AVAILABLE(10_10, 8_0) = -996,
NSURLErrorBackgroundSessionWasDisconnected NS_ENUM_AVAILABLE(10_10, 8_0)= -997,
回答by ilnar_al
I use the following method in my project
我在我的项目中使用以下方法
-(NSArray*)networkErrorCodes
{
static NSArray *codesArray;
if (![codesArray count]){
@synchronized(self){
const int codes[] = {
//kCFURLErrorUnknown, //-998
//kCFURLErrorCancelled, //-999
//kCFURLErrorBadURL, //-1000
//kCFURLErrorTimedOut, //-1001
//kCFURLErrorUnsupportedURL, //-1002
//kCFURLErrorCannotFindHost, //-1003
kCFURLErrorCannotConnectToHost, //-1004
kCFURLErrorNetworkConnectionLost, //-1005
kCFURLErrorDNSLookupFailed, //-1006
//kCFURLErrorHTTPTooManyRedirects, //-1007
kCFURLErrorResourceUnavailable, //-1008
kCFURLErrorNotConnectedToInternet, //-1009
//kCFURLErrorRedirectToNonExistentLocation, //-1010
kCFURLErrorBadServerResponse, //-1011
//kCFURLErrorUserCancelledAuthentication, //-1012
//kCFURLErrorUserAuthenticationRequired, //-1013
//kCFURLErrorZeroByteResource, //-1014
//kCFURLErrorCannotDecodeRawData, //-1015
//kCFURLErrorCannotDecodeContentData, //-1016
//kCFURLErrorCannotParseResponse, //-1017
kCFURLErrorInternationalRoamingOff, //-1018
kCFURLErrorCallIsActive, //-1019
//kCFURLErrorDataNotAllowed, //-1020
//kCFURLErrorRequestBodyStreamExhausted, //-1021
kCFURLErrorFileDoesNotExist, //-1100
//kCFURLErrorFileIsDirectory, //-1101
kCFURLErrorNoPermissionsToReadFile, //-1102
//kCFURLErrorDataLengthExceedsMaximum, //-1103
};
int size = sizeof(codes)/sizeof(int);
NSMutableArray *array = [[NSMutableArray alloc] init];
for (int i=0;i<size;++i){
[array addObject:[NSNumber numberWithInt:codes[i]]];
}
codesArray = [array copy];
}
}
return codesArray;
}
Then I just check the error code and show alert if it is in the list
然后我只检查错误代码并显示警报,如果它在列表中
if ([[self networkErrorCodes] containsObject:[NSNumber
numberWithInt:[error code]]]){
// Fire Alert View Here
}
But as you can see I commented out codes that I think does not fit to my definition of NO INTERNET. E.g the code of -1012 (Authentication fail.) You may edit the list as you like.
但是正如您所看到的,我注释掉了我认为不符合我对 NO INTERNET 的定义的代码。例如代码-1012(认证失败)。您可以随意编辑列表。
In my project I use it at username/password entering from user. And in my view (physical) network connection errors could be the only reason to show alert view in your network based app. In any other case (e.g. incorrect username/password pair) I prefer to do some custom user friendly animation, OR just repeat the failed attempt again without any attention of the user. Especially if the user didn't explicitly initiated a network call.
在我的项目中,我在用户输入的用户名/密码时使用它。在我看来(物理)网络连接错误可能是在基于网络的应用程序中显示警报视图的唯一原因。在任何其他情况下(例如不正确的用户名/密码对),我更喜欢做一些自定义的用户友好动画,或者只是在没有用户注意的情况下再次重复失败的尝试。特别是如果用户没有明确发起网络呼叫。
Regards to martinezdelariva for a link to documentation.
关于 martinezdelariva 的文档链接。
回答by Jon
I found this page in the documentation which has an objective-c enum for all of the error codes under the NSURLErrorDomain.
我在文档中找到了这个页面,其中包含 NSURLErrorDomain 下所有错误代码的 Objective-c 枚举。
回答by ben
I found a new error code which is not documented above: CFNetworkErrorCode -1022
我发现了一个上面没有记录的新错误代码:CFNetworkErrorCode -1022
Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection."