Afnetworking委托方法没有被调用

时间:2017-08-02 07:03:00

标签: ios objective-c

这是我的代码,请检查我错在哪里。获取请求后,不会调用成功或失败方法。请帮帮我。

-(void)downLoadTask {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString  *documentsDirectory = [paths objectAtIndex:0];

    NSString*  mediaKey = [NSString stringWithFormat:@"%@/Sample.m4v", documentsDirectory];
    NSLog(@"%@",mediaKey);
    NSString *strPath = @"/sites/default/files/media/Master_Talara1_9.mp4";

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:[self.HTTPClient requestWithMethod:@"GET" path:strPath parameters:nil]];

    operation.downloadSpeedMeasure.active = YES;

    [operation setShouldExecuteAsBackgroundTaskWithExpirationHandler:^{
        NSLog(@"time out");
        // Clean up anything that needs to be handled if the request times out
        // It may be useful to initially check whether the operation finished or was cancelled
    }];

    operation.outputStream = [NSOutputStream outputStreamToFileAtPath:mediaKey append:NO];

    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"Success");
    }
    failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];

    [operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
        humanReadableRemaingTime = [operation.downloadSpeedMeasure humanReadableRemainingTimeOfTotalSize:totalBytesExpectedToRead numberOfCompletedBytes:bytesRead];

        NSLog(@"Time is human read %@",humanReadableRemaingTime);           
    }];       
}

是否有任何方法可以实现调用AFNetWorking委托方法

1 个答案:

答案 0 :(得分:1)

您忘记编写代码以在功能结束时开始下载任务。

update W67U999S from 
(
    select
            b.CRDATTIM,
            b.RECORDCD,
            b.CRNODE,
            b.UNITCD,
            b.WRKTYPE


        from W67U999S a
        join W03U999S b
            on a.CCRDATTIM = b.CRDATTIM and a.CRECORDCD = b.RECORDCD and a.CCRNODE = b.CRNODE
        where a.PCRDATTIM = '2017-07-20-04.22.20.893340'
        and a.PRECORDCD = 'F'
        and a.PCRNODE = '01'
        and b.WRKTYPE = 'CALLER'
        and b.UNITCD='CS2XAA'
) X
set  W67u999s.ccrdattim= X.crdattim
where
    W67U999S.CCRDATTIM = X.CRDATTIM 
    and W67U999S.CRECORDCD = X.RECORDCD 
    and W67U999S.CCRNODE = X.CRNODE