How to fix NSURLErrorDomain error -1012 when authenticating?
I am dealing with a problem of authenticating with a Tumblr account using [NSURLConnection sendAsynchronousRequest:queue:completionHandler:]
to submit an authentication request, but here I am meeting a tough problem:
- Whenever I submit the request for the first time everything goes fine, but when the first authentication is done and then the request is resubmitted a second time , "NSURLErrorDomain error -1012" occurs.
- The authentication page is loaded into the webview so that authentication takes place in my application without a browser. But it is interesting that if the process is launched in the browser, no errors occur, errors only occur when using the webview .
- It was strange that the authentication is done with the same code, but only the first authentication can be done, only if I reinstall the app, I can authenticate it again, and after that the problem reoccurs.
- I did everything I could to solve the problem, I clear the cache and cookies in the web browser, find the authentication process to see the parameters, set the request's cachePolicy, but nothing helps.
- I also found that on ios6 the process goes without errors. But on ios7 I get -1012.
- code -1012 tells me that the user has canceled the authentication, but the process is automatic and I am not canceling it.
I'm wondering if the problem comes from NSURLConnection
.
- (void)authenticate:(NSString *)URLScheme WithViewController:(UIViewController *)con callback:(TMAuthenticationCallback)callback {
self.threeLeggedOAuthTokenSecret = nil;
self.hostViewController = con;
self.callback = callback;
[self emptyCookieJar];
NSString *tokenRequestURLString = [NSString stringWithFormat:@"http://www.tumblr.com/oauth/request_token?oauth_callback=%@", TMURLEncode([NSString stringWithFormat:@"%@://tumblr-authorize", URLScheme])];
NSLog(@"%@", tokenRequestURLString);
NSMutableURLRequest *request = mutableRequestWithURLString(tokenRequestURLString);
NSLog(@"%@", request);
[[self class] signRequest:request withParameters:nil consumerKey:self.OAuthConsumerKey
consumerSecret:self.OAuthConsumerSecret token:nil tokenSecret:nil];
[self openOAuthViewController];
NSURLConnectionCompletionHandler handler = ^(NSURLResponse *response, NSData *data, NSError *error) {
NSInteger statusCode = ((NSHTTPURLResponse *)response).statusCode;
if (error) {
if (callback) {
callback(nil, nil, error);
}
return;
}
NSLog(@"%d", statusCode);
if (statusCode == 200) {
self.threeLeggedOAuthCallback = callback;
NSDictionary *responseParameters = formEncodedDataToDictionary(data);
self.threeLeggedOAuthTokenSecret = responseParameters[@"oauth_token_secret"];
NSURL *authURL = [NSURL URLWithString:
[NSString stringWithFormat:@"http://www.tumblr.com/oauth/authorize?oauth_token=%@",
responseParameters[@"oauth_token"]]];
[self initOAuthViewControllerWithURL:authURL];
} else {
if (callback) {
callback(nil, nil, errorWithStatusCode(statusCode));
}
}
};
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:handler];
}
The code above, everything goes fine before and after this method I got an error in . [NSURLConnection sendAsynchronousRequest:queue:completionHandler:]
completionHandler
+3
source to share
No one has answered this question yet
See similar questions:
or similar: