0

I want to check if a NSURLErrorCancelled occurred. So basically mapping this SO answer to C#.

The only thing I came up with is checking the error code directly:

if(e.Error.Code != -999){
    // real error here
}

How can I compare the NSError with NSURLError.Cancelled in case the error code changes sometime?

Solution linked by David Karlaš:

var urlError = default(NSUrlError);
if(!Enum.TryParse<NSUrlError>(e.Error.Code.ToString(), out urlError)){
    urlError = NSUrlError.Unknown;
}
// this is error code -999
if(urlError != NSUrlError.Cancelled){
    // do something
}
Community
  • 1
  • 1
testing
  • 19,681
  • 50
  • 236
  • 417

1 Answers1

1

Looks like this is way to do it: Link to Github code

Also notice that UserCancelledAuthentication is handled same way in switch below... Which you might want to do as well.

David Karlaš
  • 942
  • 2
  • 6
  • 11