0
我不知道爲什麼我應用程序在這一行應用在IOS
NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
崩潰墜毀sendSynchronousRequest這是我的代碼:
NSString * urlString = [[NSUserDefaults standardUserDefaults] objectForKey:MAINURL];
NSHTTPURLResponse * response;
NSError * error;
NSMutableURLRequest *request;
request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlString]
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:120];
if([[[NSUserDefaults standardUserDefaults] objectForKey:@"callWebServiceFor"] isEqualToString:nil]) {
// [request setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"];
NSString * strSessionId = [[NSUserDefaults standardUserDefaults] objectForKey:@"sessionId"];
if(strSessionId != nil)
[request setValue:strSessionId forHTTPHeaderField:@"Cookie"];
}
NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
// Storing session headers when user logs in successfully
if([[[NSUserDefaults standardUserDefaults] objectForKey:@"callWebServiceFor"] isEqualToString:@"login"]) {
NSArray * all = [NSHTTPCookie cookiesWithResponseHeaderFields:[response allHeaderFields] forURL:[NSURL URLWithString:urlString]]; //testing
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookies:all forURL:[NSURL URLWithString:urlString] mainDocumentURL:nil];
NSString * strSessionId;
for (NSHTTPCookie *cookie in all) {
strSessionId = [[NSString alloc] initWithString:cookie.value];
// NSLog(@"Session value: %@",cookie.key];
// NSLog(@"Session value: %@",strSessionId);
}
[[NSUserDefaults standardUserDefaults] setObject:strSessionId forKey:@"sessionId"];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"callWebServiceFor"];
}
if (data != nil) {
dispatch_async(kBackGroudQueue, ^{
[self performSelectorOnMainThread:@selector(handleWebServiceResponse:)
withObject:data waitUntilDone:YES];
});
} else {
[SwapweekUtilViewController showAlert:@"Internet" :@"Check your Internet Connection"];
}
即使它不拋出任何錯誤例外 –
發佈堆棧跟蹤。 – trojanfoe