2011-10-17 56 views
0

我正在创建NSMutableRequest并将数据添加到正文。继承人的例子,我是怎么做的:如何设置正文后设置NSMutableRequest超时小于240秒?

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:stringURL] 
                  cachePolicy:NSURLRequestReloadIgnoringLocalCacheData 
                 timeoutInterval:230.0]; 
    NSLog(@"Time out interval: %f", request.timeoutInterval); >> Output: 230 

    [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]]; 

    NSLog(@"Time out interval: %f", request.timeoutInterval); >> Output: 240 
    [request setTimeoutInterval:230]; 
    NSLog(@"Time out interval: %f", request.timeoutInterval); >> Output: 240 

请求超时创建后是230 后,我设置的身体是240 后,我将其重置为230。它仍然是240超时值不除非我把它设置得更大才改变?

任何人都有任何想法为什么发生?如何使超时间隔小于240秒?

回答

1

在iOS上,您只能以这种方式指定超过240秒的超时时间(因为iPhone可能运行速度很慢)。更多详情请查看:https://devforums.apple.com/message/108292#108292

如果你真的需要更短的超时时间,你可以使用NSTimer。 在这种情况下,只要记住使用异步请求,这可以很容易地取消。