【发布时间】:2015-11-02 08:00:04
【问题描述】:
我在 Xcode 6.4 上构建了一个项目。它工作正常。但是在我将 Xcode 升级到 Xcode 7 的那一天,所有的 JSON 服务都无法正常工作并且总是给我错误。 这是我的代码
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);
}
它在 Xcode 6 上仍然可以正常工作
这是错误日志
Error Domain=NSURLErrorDomain Code=-1022 "资源不能被 加载,因为应用程序传输安全策略需要使用 安全连接。”
【问题讨论】:
-
能贴出错误日志吗?
-
我已经更新了我的问题.. 请看看@Anbu.Karthik 和 Leo
标签: ios objective-c iphone json xcode