2011-12-30 30 views

回答

1

我做的是這樣的:我創建了NSString *origiOS4,如果運行的操作系統是iOS4,那麼我初始化字符串並給它一個url值。在connection:didReceiveData:方法中,我讀取了origiOS4的值。

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { 
    float version = [[[UIDevice currentDevice] systemVersion] floatValue]; 
    if (version < 5) { 
     origiOS4 = [[NSString alloc] initWithString:response.URL.absoluteString]; 
    } 
} 
+0

我正在潛入已有的代碼,我發現它在4.3中突破。這爲我修好了。 – jaime 2012-10-06 05:02:26

3

讀NSURLConnection.h頭文件 - 你會看到這樣的評論:

When created, an NSURLConnection performs a deep-copy of the 
    NSURLRequest. This copy is available through the 
    -originalRequest method. As the connection performs the load, 
    this request may change as a result of protocol 
    canonicalization or due to following redirects. 
    -currentRequest can be used to retrieve this value. 

由於這種方法是在iOS5中推出,你將無法在的iOS4.3使用它或更早。所以在這種情況下,您需要複製新方法的功能。

如果您使用的是非常簡單的NSURLRequest對象,它可能與在初始化NSURLConnection之前執行[請求副本]一樣簡單,否則您需要查看如何實現深度複製。 NSURLRequest確實實現了NSCoding,因此,如果這是您需要的,您可以將其歸檔並取消歸檔以製作深層副本。

相關問題