kCFErrorDomainCFNetwork error -1005 AFNetworking - ios

I have a singleton class:
+(id)sharedClient
{
static HackerNewsClient *__instance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSURL *url = [NSURL URLWithString:#"http://node-hnapi.herokuapp.com"];
__instance = [[HackerNewsClient alloc] initWithBaseURL:url];
});
return __instance;
}
And in a controller I am calling this like so:
[[HackerNewsClient sharedClient]GET:#"/news"
parameters:nil
success:^(NSURLSessionDataTask *task, id responseObject) {
NSArray *posts = [self parseEpisodeJSONData:responseObject];
completion(posts);
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(#"ERROR: %#", error);
}];
The url this creates is http://node-hnapi.herokuapp.com/news which is a valid and working url. But the error message returned is
2014-07-08 08:51:15.942 hn[27435:1627947] ERROR: Error Domain=NSURLErrorDomain Code=-1005 "The operation couldn’t be completed. (NSURLErrorDomain error -1005.)" UserInfo=0x10ba2bf70 {NSErrorFailingURLStringKey=http://node-hnapi.herokuapp.com/news, NSErrorFailingURLKey=http://node-hnapi.herokuapp.com/news, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=57, NSUnderlyingError=0x10ba22ff0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1005.)"}
I can't work out what would be causing this issue. Thanks

this error always appeared when the connection fails ..
if your connection work fine just try to restart the iPhone simulator spicily with iPhone 6 simulator ...!
check link : NSURLConnection GET request returns -1005, "the network connection was lost"

Look in the CFNetworkErrors header files for CFNetwork Framework.
In Xcode navigate to
ProjectName > Frameworks > CFNetwork.framework > Headers > CFNetworkErrors.h

Related

AFNetworking 3.0 iOS 9.3.5 reject some SSL

This happened only in iOS 9.3.5 (not sure about other 9 or below), not occur in iOS 10.x.
When I use AFNetworking to connect to an API URL, it just run into failure callback with error like below:
LOG: Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to
the server." UserInfo={NSErrorFailingURLStringKey=APIURL,
_kCFStreamErrorCodeKey=-2200, NSErrorFailingURLKey=APIURL, NSLocalizedDescription=Could not connect to the server.,
_kCFStreamErrorDomainKey=4, NSUnderlyingError=0x16146990 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)"
UserInfo={_kCFStreamErrorDomainKey=4, NSErrorPeerAddressKey={length =
16, capacity = 16, bytes = 0x100201bb253ce7160000000000000000},
_kCFStreamErrorCodeKey=-2200}}}
When I paste the API to safari browser (same device), it ask me to trust a certificate or something like that, so I'm afraid there's something wrong in the configuration in the app.
My call for URL:
self.sessionManager = [[AFHTTPSessionManager alloc] initWithBaseURL:baseUrl sessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
self.sessionManager.securityPolicy.allowInvalidCertificates = YES;
self.sessionManager.securityPolicy.validatesDomainName = NO;
self.sessionManager.requestSerializer.timeoutInterval = timeout;
self.sessionManager.requestSerializer = [AFJSONRequestSerializer serializer];
// Call API:
[self.sessionManager POST:path parameters:dictParams progress:nil success:^(NSURLSessionTask *task, id responseObject) {
// success block
} failure:^(NSURLSessionTask *task, NSError *error) {
// failure block
}
I've even set NSAllowsArbitraryLoads=true in App Transport Security Settings inside info.plist.
How to fix this? I found this question have the similar error, but I'm not so sure. I don't have access to the API host and in ios 10.x it works just fine. When using postman it works too.

NSURLErrorDomain code=-1005 from GKLeaderboard loadScoresWithCompletionHandler:

I am receiving the following error in a callback to loadScoresWithCompletionHandler:
Error Domain=NSURLErrorDomain Code=-1005
"The operation couldn’t be completed. (NSURLErrorDomain error -1005.)"
Other calls to Game Center both before and afterwards succeed. (They operate on various threads). If have initialized the leaderboard request as follows:
GKLeaderboard *leaderboard = [[GKLeaderboard alloc] init];
leaderboard.identifier = leaderboardIdentifier; // valid identifier
leaderboard.playerScope = GKLeaderboardPlayerScopeFriendsOnly;
leaderboard.range = NSMakeRange(1, 100); // max. allowed range.
leaderboard.timeScope = GKLeaderboardTimeScopeAllTime;
[leaderboard loadScoresWithCompletionHandler:^(NSArray *scores, NSError *error) {
// ...
}];
What is going on here and how can I overcome this problem?
The calls to loadScoresWithCompletionHandler: are made from an operation on an NSOperationQueue whose task it is to issue requests for scores (I am interested in each localPlayerScore) to several leaderboards and wait for all responses. The first response already carries the error.
UPDATE -1005 denotes kCFURLErrorNetworkConnectionLost; the underlying cause is still unclear.
UPDATE If I send only a single request (instead of as so far typically 6 in parallel) I receive error NSURLErrorDomain -1001, which denotes kCFURLErrorTimedOut, or GKErrorDomain 3 ...
For some reason this alternative call does not lead to errors:
GKLeaderboard *leaderboard =
[[GKLeaderboard alloc] initWithPlayers:#[ GKLocalPlayer.localPlayer ]];
leaderboard.identifier = leaderboardIdentifier;
leaderboard.timeScope = GKLeaderboardTimeScopeAllTime;
[leaderboard loadScoresWithCompletionHandler:^(NSArray *scores, NSError *error) {
// ...
}];
Problem solved.

NSCocoaErrorDomain = 256

I'm using this code to get the php page response from a GET call from my iOS app.
NSLog(#"%#", parameters);
// Send data to the web services
NSError *error;
NSString *result = [NSString stringWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://178.63.103.3/hermes-resource/ws.php%#", parameters]] encoding:NSUTF8StringEncoding error:&error];
NSLog(#"%#", error);
NSString *result_;
if (result)
{
result_ = [self convert:result];
}
That's the error I got from stringWithContentsOfURL method and the log of parameters string.
2014-07-18 11:44:51.036 Hermes[542:60b] ?name=Luca D'Alberti&email=email#ext.it&range=21-39&graphic=5&userx=1&gamed=Si&comment_game=&errors=No&comment_errors=&feed=Fvdgd fvdgd
2014-07-18 11:44:51.042 Hermes[542:60b] Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)"
Why this error do occur?
The error is NSFileReadUnknownError source: Foundation Constants

AFNetworking request with Basic Auth works at first but fails after a few minutes

I have an app with data fed from an AFNetworking request with basic auth. I have a refresh button to perform the same function used to initially feed the data. This all works, but after a couple minutes it doesn't.
My code:
- (void) refreshData
{
// Show loading
NSLog(#"Refreshing...");
[LoadingView initInView:self.view];
// Get session data for auth key
SessionHelper *session = [SessionHelper sharedInstance];
// Setup request
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager setRequestSerializer:[AFHTTPRequestSerializer serializer]];
[manager.requestSerializer clearAuthorizationHeader];
[manager.requestSerializer setAuthorizationHeaderFieldWithUsername:session.authKey password:#""];
NSString *url = #"https://myurl.com/getdata";
[manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
self.data = [[NSMutableArray alloc] init];
[self.data addObjectsFromArray:responseObject];
[self.tableView reloadData];
[LoadingView remove];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(#"Error: %#", [error description]);
[operation cancel];
}];
}
Works repeatedly fine at first, but after a few minutes it hangs with the loading screen (from LoadingView) and the error:
Error: Error Domain=NSURLErrorDomain Code=-1012 "The operation
couldn’t be completed. (NSURLErrorDomain error -1012.)"
UserInfo=0x8a5ed20 {NSErrorFailingURLKey=https://myurl.com/getdata,
NSErrorFailingURLStringKey=https://myurl.com/getdata}
I thought maybe I needed to do clearAuthorizationHeader or something, but no go. Any ideas? Thanks!
Update: Logging operation.response.statusCode in the error message
gives me 0.
Update 2: Using AFNetworkActivityLogger gives me this after it starts failing:
2014-02-26 13:23:02.206 MyApp iPad[4087:60b]
GET 'https://myurl.com/getdata' 2014-02-26 13:23:02.646 MyApp
iPad[4087:60b] [Error] GET '(null)' (0) [0.4332 s]: Error
Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be
completed. (NSURLErrorDomain error -1012.)" UserInfo=0x17d9a990
{NSErrorFailingURLKey=https://myurl.com/getdata,
NSErrorFailingURLStringKey=https://myurl.com/getdata} 2014-02-26
13:23:02.648 MyApp iPad[4087:60b] Error: Error Domain=NSURLErrorDomain
Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain
error -1012.)" UserInfo=0x17d9a990
{NSErrorFailingURLKey=https://myurl.com/getdata,
NSErrorFailingURLStringKey=https://myurl.com/getdata}, Status Code: 0
Seems the URL is being sent as (null)...
Turns out, even though the GoDaddy certificate I'm using looks to be valid and supported by iOS 7 according to http://support.apple.com/kb/HT5012, adding this bit solves the problem. Seems to kind of defeat the purpose, but it works. I won't accept this answer yet in case someone can give some insight / something more helpful.
AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
securityPolicy.allowInvalidCertificates = YES;
manager.securityPolicy = securityPolicy;

creating event using facebook sdk 3.1

i am trying to create an event but getting error . i am writing following code to create event using facebook sdk 3.1
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"My Test Event",#"name",
#"Bangalore",#"location",
#"1297641600",#"start_time",
#"1297468800",#"end_time", nil];
NSString * pRequest = [NSString stringWithFormat:#"me/events"];
[FBRequestConnection startWithGraphPath:pRequest parameters:params HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error)
{
NSLog(#"Facebook Post Success..");
} else
{
NSLog(#"Facebook Post Failed..");
NSLog(#"ERROR : %#", error.localizedDescription);
}
}];
error :
Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0xa180200 {com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 100;
message = "(#100) Invalid parameter";
type = OAuthException;
};
};
code = 400;
}, com.facebook.sdk:HTTPStatusCode=400}
can anybody help .....
thanks in advance
The error is a 400 error a bad request. This means there is something wrong with you're request. Also the error that Facebook returns suggest that you have an invalid parameter. So I suggest to double check you're parameters that you are sending and make sure you sending the correct amount of parameters in the right order and the right values.

Resources