AFN three-party file monitoring network status request network data

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.