Ios – NSURLErrorDomain Code=-1012 The operation couldn’t be completed

iosnserrornsmutableurlrequestobjective-cssl-certificate

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

Best Solution

In my case i am making a very silly mistake.

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

This solved my problem

Related Question