Last active
November 2, 2017 03:18
-
-
Save yuchuanfeng/21299c03d269fdbe81bbd79f639a4ca0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "ViewController.h" | |
#import <AFNetworking/AFNetworking.h> | |
@interface ViewController () | |
@end | |
static dispatch_queue_t _queue; | |
@implementation ViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
_queue = dispatch_get_global_queue(0, 0); | |
dispatch_async(_queue, ^{ | |
NSLog(@"start-----"); | |
[self getNetwork]; | |
NSLog(@"end-----"); | |
}); | |
} | |
- (void)getNetwork { | |
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; | |
manager.responseSerializer = [AFHTTPResponseSerializer serializer]; | |
dispatch_semaphore_t semphore = dispatch_semaphore_create(0); | |
NSString* urlStr = @"http://www.weather.com.cn/data/sk/101010100.html"; | |
[manager GET:urlStr parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) { | |
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { | |
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:(NSData *)responseObject options:0 error:nil]; | |
NSLog(@"result: %@", json); | |
dispatch_semaphore_signal(semphore); | |
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { | |
}]; | |
dispatch_semaphore_wait(semphore, DISPATCH_TIME_FOREVER); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment