• AFNetworking 请求队列


    新鲜出炉 AFNetworking 请求队列

    NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];

        NSURLRequest *request = [NSURLRequest requestWithURL:url];

        AFHTTPRequestOperation *operation1 = [[AFHTTPRequestOperation alloc] initWithRequest:request];

        [operation1 setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

            NSLog(@"Response: %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]);

        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

            NSLog(@"Error: %@", error);

        }];

        

        

        NSURL *url2 = [NSURL URLWithString:@"http://www.sohu.com"];

        NSURLRequest *request2 = [NSURLRequest requestWithURL:url2];

        AFHTTPRequestOperation *operation2 = [[AFHTTPRequestOperation alloc] initWithRequest:request2];

        [operation2 setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

            NSLog(@"Response2: %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]);

        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

            NSLog(@"Error: %@", error);

        }];

        

        

        

        NSURL *url3 = [NSURL URLWithString:@"http://www.sina.com"];

        NSURLRequest *request3 = [NSURLRequest requestWithURL:url3];

        AFHTTPRequestOperation *operation3 = [[AFHTTPRequestOperation alloc] initWithRequest:request3];

        [operation3 setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

            NSLog(@"Response3: %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]);

        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

            NSLog(@"Error: %@", error);

        }];

        

        

        //同时请求

        NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];

        [operationQueue setMaxConcurrentOperationCount:3];

        [operationQueue addOperations:@[operation1, operation2, operation3] waitUntilFinished:NO];

     

        

        //operation2 operation1 请求完成后执行

        NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];

        [operation2 addDependency:operation1];

        [operationQueue addOperations:@[operation1, operation2, operation3] waitUntilFinished:NO];

  • 相关阅读:
    vertical blank interrupt 和 horizontal blank interrupt解释
    X server和windows manager的关系
    Kconfig中的select和depends on
    Debugging the kernel using Ftrace part 3
    Kernel: printk's no_console_suspend
    sql分割函数|在网上找的看着挺好,谁的忘了
    Ajax处理函数模板
    新闻添加html页面
    页码控件源码|分页页码控件源码
    谷歌本地商户中心 |谷歌本地商户中心 介绍|谷歌本地商户中心 网址
  • 原文地址:https://www.cnblogs.com/kkkblog/p/4126509.html
Copyright © 2020-2023  润新知