Before Hit API set Secure connection

open Info.plist

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”&gt;

<plist version=”1.0″>

<dict>

<key>NSAllowsArbitraryLoads</key>

<true/>

<key>NSExceptionDomains</key>

<dict>

<key>akamaihd.net</key>

<dict>

<key>NSIncludesSubdomains</key>

<true/>

<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>

<false/>

</dict>

<key>facebook.com</key>

<dict>

<key>NSIncludesSubdomains</key>

<true/>

<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>

<false/>

</dict>

<key>fbcdn.net</key>

<dict>

<key>NSIncludesSubdomains</key>

<true/>

<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>

<false/>

</dict>

</dict>

</dict>

</plist>

Hit API with NSURLSession get response

<NSURLSessionDelegate>

-(void)getJsonResponse : (NSString *)urlStr success : (void (^)(NSDictionary *responseDict))success failure:(void(^)(NSError* error))failure

{

    

    

    NSURLSession * session = [NSURLSession sharedSession];

    NSURL * url = [NSURL URLWithString: urlStr];

    

    

    // Asynchronously Api is hit here

    NSURLSessionDataTask * dataTask = [session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)

                                       {

                                           

                                           NSLog(@”%@”,data);

                                           

                                           NSDictionary * json  = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

                                           NSLog(@”%@”,json);

                                           success(json);

                                           

                                           

                                           

                                       }];

    

    [dataTask resume] ; // Executed First

    

    

}

Leave a comment