NSURL 、NSURLRequest、NSURLConnection、NSURLSession、NSURLSessionDataTask

来源:互联网 发布:铣刀移动网络销售 编辑:程序博客网 时间:2024/05/17 03:00

NSString ---> NSURL --> NSURLRequest --> NSURLConnection  被弃用

+ (nullable NSData *)sendSynchronousRequest:(NSURLRequest *)request returningResponse:(NSURLResponse * __nullable * __nullable)response error:(NSError **)errorNS_DEPRECATED(10_3,10_11, 2_0,9_0,"Use [NSURLSession dataTaskWithRequest:completionHandler:] (see NSURLSession.h");


+ (void)sendAsynchronousRequest:(NSURLRequest*) request

                          queue:(NSOperationQueue*) queue

              completionHandler:(void (^)(NSURLResponse*__nullable response, NSData*__nullable data, NSError*__nullable connectionError)) handler NS_DEPRECATED(10_7,10_11, 5_0,9_0,"Use [NSURLSession dataTaskWithRequest:completionHandler:] (see NSURLSession.h");



NSString ---> NSURL --> NSURLRequest --> NSURLSession --> NSURLSessionDataTask

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:@"https://github.com"]];  NSURLSession *session = [NSURLSession sharedSession];  NSURLSessionDataTask *task = [session dataTaskWithRequest:request                                         completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {                                           NSString *dataStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];                                           NSLog(@"%@", dataStr);                                       }];[task resume];



0 0
原创粉丝点击