我在Xcode 6.4上創建了一個項目。它工作正常。但是當我將Xcode升級到Xcode 7時,所有的JSON服務都無法正常工作,並且總是給我錯誤。 這裏是我的代碼xcode 7 json總是在目標中顯示錯誤C
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
這裏做工精細的錯誤日誌
錯誤域= NSURLErrorDomain代碼= -1022「的資源不能 裝因爲應用傳輸安全策略要求使用 安全連接。「
顯示你的錯誤 –
你能發佈錯誤日誌嗎? – Leo
我已更新我的問題..請看看@ Anbu.Karthik和Leo –