How to Solve Control reaches end of non-void block

When using afn3.0


We made the following mistakes

Control reaches end of non-void block 。

This block should have a return value, but you didn’t report an error.

The specific uses are as follows:

    AFHTTPSessionManager *httpMgr = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    NSURLSessionDataTask *task = [httpMgr HEAD:[self.url absoluteString] parameters:nil success:^(NSURLSessionDataTask * _Nonnull task) {
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    //By default, when the server response is received, the server thinks the client does not need to receive data, so the proxy method will not be called afterwards
    // If you need to continue receiving data from the server, then you need to call block, and pass in the corresponding policy

        NSURLSessionResponseCancel = 0, Cancel task
        NSURLSessionResponseAllow = 1, Receive task
        NSURLSessionResponseBecomeDownload = 2, turn into a download
        NSURLSessionResponseBecomeStream NS_ENUM_AVAILABLE(10_11, 9_0) = 3, turn into a stream

    [httpMgr setDataTaskDidReceiveResponseBlock:^NSURLSessionResponseDisposition(NSURLSession * _Nonnull session, NSURLSessionDataTask * _Nonnull dataTask, NSURLResponse * _Nonnull response) {
      // If the NSURLSessionResponseDisposition method is not returned here, this error will be reported
       // Solution Pass in the corresponding policy e.g.
        return NSURLSessionResponseBecomeDownload;

Or when using AFN’s download task:

    [sessonMgr downloadTaskWithRequest:[NSURLRequest requestWithURL:self.url] progress:^(NSProgress * _Nonnull downloadProgress) {
    } destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
       // This error will also be reported if the stored directory is not returned here.
        return [NSURL URLWithString:self.destPath];
    } completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {


This question is answered on stackOverFlow:

Similar Posts: