Reputation: 975
I had build a project on Xcode 6.4 . It was working fine . But the day i have upgraded my Xcode to Xcode 7, all the JSON services are not working and always giving me error . Here is my code
NSDictionary *get = @{@"name":name.text,@"username":username.text,@"mobile":phonenumber.text};
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:get options:kNilOptions error:nil];
NSString *jsonInputString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSString *post = [[NSString alloc]initWithFormat:@"r=%@",jsonInputString];
NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"%@",registerUrl]];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:120.0];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSError *error;
NSURLResponse *response;
NSData *responseData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (responseData != nil)
{
NSMutableDictionary *jsonDict = (NSMutableDictionary *)[NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
NSLog(@"Json Dictionary =======%@",jsonDict);
}
if (error)
{
NSLog(@"error %@",error.description);
}
It is still working fine on Xcode 6
Here is Error log
Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection."
Upvotes: 0
Views: 312
Reputation: 519
You can set some NSAppTransportSecurity values in your plist.
If you're connecting to a third party, they most surely have a secure server. If it's your own server, you can get a cheap signed certificate.
Upvotes: 0
Reputation: 11039
Open your Info.plist
file, add a new row with name NSAppTransportSecurity
and type of Dictionary
. Then add a new row in it with name NSAllowsArbitraryLoads
and type of bool
and set value to YES.
Upvotes: 2