2011-10-17 62 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。 在這種情況下,只要記住使用異步請求,這可以很容易地取消。