Afnetworking three-party file to request network data first-Step header file
#import "AFNetworking.h"
The second step is to create the manager for network requests
AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
The third step: to make a network request because of our interface problem, we need to add an @ "text/html" in the afurlresponseserialization.m file in the No. 222 line add @ "text/html" The original code
[manager GET:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/movielist.php" parameters:nilid responseObject) {
Put the data in the model
self.movieArr =[NSMutableArray array];NSMutableDictionary *dic =responseObject;for (NSMutableDictionary *temp in dic[@"result"]) { Movie *movie =[[Movie alloc] init]; [movie setValuesForKeysWithDictionary:temp]; [self.movieArr addObject:movie]; } [self.movieTableView reloadData]; NSError *error) {}];
Detection of network status using Afnetworkreachabilitymanager three-party file detect current network status
AFNetworkReachabilityManager *manager=[AFNetworkReachabilityManager sharedManager];
Start the network detection
[manager startmonitoring]; [Manager setreachabilitystatuschangeblock:^ (Afnetworkreachabilitystatus status) {//inside to determine the current network situation if (Status = = 0 ) {nslog (@" Not Connected "); }else if (Status = = 1 ) {nslog (@ "2g/3g Network" ); }else if (Status = = 2 ) {nslog (@ "WiFi" ); }else {nslog (@ "not Network "); } }];
Stop detection
[manager stopMonitoring];
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
AFN three-party file monitoring network status request network data