IT박스

iOS의 NSURLErrorDomain 오류 코드 -999

itboxs 2020. 11. 20. 08:45

iOS의 NSURLErrorDomain 오류 코드 -999


저는 Corona SDK의 Facebook API를 사용하여 제가 페이스 북에서 개발중인 게임에 점수를 게시하려고했습니다. 그러나 나는 그것에 문제가 있습니다. 처음으로 페이스 북에 게시하려고 할 때 로그인 및 사용자 인증 후이 오류가 발생합니다.

NSURLErrorDomain 오류 코드 -999

그러면 페이스 북에 게시되지 않습니다. 이 오류의 가능한 원인은 무엇이며 어떻게 해결할 수 있습니까? 웹 검색을 시도했지만 정보를 찾을 수 없습니다. 미리 감사드립니다.

그건 그렇고, 내 앱에서 webview를 사용하지 않습니다. 내 Facebook 클래스의 위젯 API와 show_dialog 리스너 만 있으면됩니다.


오류는 Mac 개발자 라이브러리 (iOS 문서) 에 문서화되었습니다.

문서의 관련 세그먼트는 다음과 같습니다.

URL 로딩 시스템 오류 코드

이러한 값은 도메인이 "NSURLErrorDomain"인 NSError 개체의 오류 코드 속성으로 반환됩니다.

enum
{
   NSURLErrorUnknown = -1,
   NSURLErrorCancelled = -999,
   NSURLErrorBadURL = -1000,
   NSURLErrorTimedOut = -1001,

보시다시피, -999에 의해 발생합니다 ErrorCancelled. , 이전 요청이 완료되기 전에 다른 요청이 이루어집니다.


hjpotter92가 절대적으로 맞습니다. 저는 제 사건에 대한 해결책을 제공하고 싶습니다. 바라건대 그것은 당신에게도 유용합니다. 내 상황은 다음과 같습니다.

로그인 페이지에서> 로그인> 로딩 대화 상자 팝업> 로그인 서비스 호출> 대화 상자 닫기> 다른 화면 푸시> 다른 서비스 호출-> 오류 -999 발생

이 문제를 해결하기 위해 대화 상자를 닫고 새 화면을 푸시하는 사이에 지연을 두었습니다.

    [indicatorAlert dismissWithClickedButtonIndex:0 animated:YES];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
                [self performSegueWithIdentifier:@"HomeSegue" sender:nil];
            });

이 문제는 iOS 7에서만 발생하는 것이 이상합니다.


여기에 추가하고 싶었습니다 -999 "cancelled". 문제를 받으면 일반적으로 다음 두 가지 중 하나입니다.

  • 똑같은 요청을 다시 실행하고 있습니다.
  • manager너무 일찍 할당 해제 된 개체에 대한 약한 참조를 유지하고 있습니다. (강력한 참조 만들기)

Alamofire를 사용할 때, 나는 코로나 SDK의 페이스 북 API를 사용하지 않았다하지만이 문제가 발생 secondRequest항상 오류 -999과 실행의 취소 나 인터넷에있는 글에 따르면, 이유는 즉 session재산은 deinit비동기 작업의 완료 이후 전 범위를 벗어 deinit났으므로 마침내 세션 속성 으로이 문제를 수동 으로 해결 하여 컴파일러가 잘못된 위치에서 정의하지 않도록합니다.

class SessionManager {
    var session:SessionManager?

    init() {
        self.session = SessionManager(configuration:URLSessionConfiguration.ephemeral)
    }
    private func firstRequest() {
        guard let session = self.session else {return}
        session.request(request_url).responseData {response in
            if let data=response.data {
                self.secondRequest()
            }
    }
    private func secondRequest() {
        guard let session = self.session else {return}
        session.request(request_url).responseData {response in
            if let data=response.data {
                self.secondRequest()
            }
            //session will no longer be needed, deinit it
            self.session = nil
    }

    }

Ramon이 작성한 것 외에도 다음을 수신 할 때 세 번째 가능한 이유가 있습니다 NSURLErrorDomain -999 cancelled.

You cancelled the task while it was executing either by calling .cancel() on the datatask object or because you used .invalidateAndCancel() on the session object. If you are creating a custom session with a delegate, you should call .invalidateAndCancel() or .finishTasksAndInvalidate() to resolve the strong reference between the session and its delegate, as mentioned in the Apple Developer Documentation:

The session object keeps a strong reference to the delegate until your app exits or explicitly invalidates the session. If you don’t invalidate the session, your app leaks memory until it exits.

If you are wondering about this logging behaviour, I found the following explanation in the Apple Developer forums:

By way of explanation, back in iOS 10 we introduced a new logging system-wide logging architecture (watch WWDC 2016 Session 721 Unified Logging and Activity Tracing for the details) and lots of subsystem, including CFNetwork, are in the process of moving over to that. Until that move is fully finished you’re going to encounter some weird edge cases like this one.


I have faced the same error with Alamofire and it was because the certificate pinning. The certificate wasn't valid anymore, so I had to remove it and add the new one. Hope it helps.


Our company's app has many -999 error in iOS. I have searched around, find the reason has two, like the network task has been dealloc or the certificate isn't valid. But I have checked our code, these two aren't possible. I am using Alamofire which is using URLSession. Luckily, our company's android app's network is normal. So we check the difference. We found the http request from iOS is Http2.0, while android is Http1.1. So we force the backend http support version down to http1.1, then -999 error count descends!!!

I think there maybe some bug in Apple's URLSession. Check the link New NSURLSession for every DataTask overkill? for some detail thoughts


I was getting this error in iOS specific version of Xamarin app. Not sure the underlying cause, but in my case was able to work around it by using post method instead of get for anything passing the server context in the request body -- which makes more sense anyway. Android / Windows / the service all handle the GET with content, but in iOS app will become partially unresponsive then spit out the 999 NSUrlErrorDomain stuff in the log. Hopefully, that helps someone else running into this. I assume the net code is getting stuck in a loop, but could not see the code in question.


For my Cordova project (or similar), turns out it was a plugin issue. Make sure you're not missing any plugins and make sure they're installed properly without issue.

Easiest way to verify this is simply to start fresh by recreating the Cordova project (cordova create <path>) along with the required platforms (cordova platform add <platform name>) and add each plugin with the verbose flag (--verbose) so that you can see if anything went wrong in the console log while the plugin is being downloaded, added to project and installed for each platform (cordova plugin add cordova-plugin-device --verbose)

Recap: cordova create <path> cordova platform add <platform name> cordova plugin add cordova-plugin-device --verbose

참고URL : https://stackoverflow.com/questions/16073519/nsurlerrordomain-error-code-999-in-ios