5

I am getting the following error when running my code from the xcode.

Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)" UserInfo=0x17166b740 {NSErrorFailingURLStringKey=https://..../move/resource/v1/user/me/activity/summary?start_date=2015-01-21&end_date=2015-01-14&detail=true, NSUnderlyingError=0x17405b630 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1012.)", NSErrorFailingURLKey=https://..../move/resource/v1/user/me/activity/summary?start_date=2015-01-21&end_date=2015-01-14&detail=true}

Here is my Code

  NSString *urlSummaryString = [[NSString stringWithFormat: @"%@summary?start_date=%@&end_date=%@&detail=true", kMisfitCloudEndpoint, strStartDate,strEndDate] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    __block NSMutableDictionary *responseDict = [NSMutableDictionary dictionary];
    __block NSError *error = nil;
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlSummaryString] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20.0];
    [request setValue:@"access_token" forHTTPHeaderField:self.misfitAccessToken];
    [request setHTTPMethod:@"GET"];
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if(connectionError){
            // Handle the connection error
            return ;
        }}];

Can any one help me what is wrong here. Is it something related to SSL Certificate on the server and is related to the security. When I use CocoaRestClient to make my request it works perfectly.

Can some body explain me in detail what cause this problem or if any body can have the solution for this. I have to use [NSURLConnection sendAsynchronousRequest] method. I am using Xcode 6.1 and ios 8.1.2

Clad Clad
  • 2,653
  • 1
  • 20
  • 32
Abdul Samad
  • 5,748
  • 17
  • 56
  • 70
  • You have tried to use NSURLRequest instead of NSMutableURLReques? I think your error is **NSURLErrorUserCancelledAuthentication**. Look this question http://stackoverflow.com/questions/22111801/ios-cant-perform-http-get-request-error-domain-nsurlerrordomain-code-1012 – weso Jan 21 '15 at 14:49
  • i have to add header and GET method to the URLRequest thats why i have to use MSMutableURLRequest. I did not get you point. – Abdul Samad Jan 21 '15 at 14:56
  • Check that before you make the call the access_token param is enhanced – weso Jan 21 '15 at 15:01
  • Try to restart your simulator. – gabbler Jan 21 '15 at 15:49

2 Answers2

2

In my case i am making a very silly mistake.

[request setValue:self.misfitAccessToken forHTTPHeaderField:@"access_token" ];

This solved my problem

Abdul Samad
  • 5,748
  • 17
  • 56
  • 70
  • I am facing same problem when i do not set Access Token, but when i set the access token in header every thing work like a charm. – Abuzar Amin Nov 18 '16 at 15:52
2

This is kCFURLErrorUserCancelledAuthentication error, -10xx errors are of the CFNetworkErrors enum. Name of this constant is pretty selfexplanatory. Server cancelled authentication for some reason

user1232690
  • 481
  • 5
  • 16