0
こんにちは私はNSurlConnectionを使ってプロジェクトを持っています。私はNSUrlSessionで置き換えたいだけです。フォローはコードの変更です。NSUrlConnectionをNSUrlSessionに置き換えてください。
- (IBAction)getResponse:(id)sender
{
[status setText:@"Retrieving response async"];
[response setText:@""];
NSURL *requestUrl = [[NSURL alloc] initWithString:url.text];
NSURLRequest *request = [NSURLRequest requestWithURL:requestUrl cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
}
- (void)connection:(NSURLConnection *) connection didReceiveResponse:(NSURLResponse *)response
{
NSLog(@"Response recieved");
}
- (void)connection:(NSURLConnection*) connection didReceiveData:(NSData *)data
{
NSLog(@"Data recieved");
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
[response setText:responseString];
[status setText:@"Response retrieved async"];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
}