저는 afnetworking 2.0을 사용하여 YouTube 동영상을 표시하고 있습니다. 연결 오류가 발생하면 경고보기를 열고 "확인"을 클릭하면 요청을 중지하고 싶습니다.AF 네트워킹 실패 블록
경고보기가 올바르게 표시되지만 "확인"을 클릭하면 요청이 중지되지 않고 작업 표시기가 나타납니다.
어떻게 요청을 중지 할 수 있습니까?
이 아래의 코드는 다음과 같습니다
-(void)loadData {
NSString *urlAsString = @"https://gdata.youtube.com/feeds/api/videos?q=wankel&v=2&max-results=50&alt=jsonc";
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] init];
activityIndicator.color = [UIColor blackColor];
activityIndicator.backgroundColor = [UIColor blackColor];
[activityIndicator startAnimating];
[self.view addSubview:activityIndicator];
activityIndicator.center = CGPointMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2);
NSURL *url = [NSURL URLWithString:urlAsString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
self.moviesArray = [responseObject valueForKeyPath:@"data.items"];
NSLog(@"%@", moviesArray);
self.thumbnailsArray = [responseObject valueForKeyPath:@"data.items.thumbnail"];
self.moviesDetailArray = [responseObject valueForKeyPath:@"data.items"];
[activityIndicator setHidden:YES];
[activityIndicator stopAnimating];
[self.collectionView reloadData];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
UIAlertView *alertView =[[UIAlertView alloc] initWithTitle:@"Error" message:[NSString stringWithFormat:@"%@", error.localizedDescription] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Try again", nil];
[activityIndicator setHidden:YES];
[activityIndicator stopAnimating];
[alertView show];
}];
[operation start];
}
"중지 요청을 afnetworking"인터넷 검색을 시도하십시오. 여기에는 이미 여러 가지 스택 오버플로 문제가 있습니다. – hgwhittle