2009-11-24 228 views
0

當我打電話iPhone緩存問題

-(IBAction)goback:(id)sender 
{ 
    NSURL *xmlURL=[NSURL URLWithString:@"http://demo.komexa.com/sicherungsbereich.xml"]; 
    NSURLRequest *request = [NSURLRequest requestWithURL:xmlURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:2]; 
    NSURLResponse *theResponse; 
    NSError *theError; 
    NSData *myRequestResult = [NSURLConnection sendSynchronousRequest:request returningResponse:&theResponse error:&theError]; 
    NSString *stringReply = (NSString *)[[NSString alloc] initWithData:myRequestResult encoding:NSUTF8StringEncoding]; 
    NSLog(@"reply from server: %@", stringReply); 
} 

與iPhone,在模擬器上加載字符串每次真正從internet.But的設備上,它緩存的字符串,所以即使http://demo.komexa.com/sicherungsbereich.xml內容更改(您可以通過調用http://demo.komexa.com來實現),字符串不會自動重新加載新數據。

你有想法嗎?

我已經在這裏上傳,因爲格式問題的代碼,: http://demo.komexa.com/problem.txt

+0

- (IBAction爲)GoBack的:(ID)發送方 { NSURL * XMLURL = [NSURL URLWithString:@ 「http://demo.komexa.com/sicherungsbereich.xml」]; NSURLRequest * request = [NSURLRequest requestWithURL:xmlURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:2]; NSURLResponse * theResponse; NSError * theError; NSData * myRequestResult = [NSURLConnection sendSynchronousRequest:request returningResponse:&theResponse error:&theError]; NSString * stringReply =(NSString *)[[NSString alloc] initWithData:myRequestResult encoding:NSUTF8StringEncoding]; (@「從服務器回覆:%@」,stringReply); } – Ploetzeneder

+0

要格式化代碼,只需選擇代碼塊並用1和0按鈕或在每行代碼前放4個空格。 –

+0

好的,謝謝你的提示。有沒有人有另一種想法如何解決這個問題 – Ploetzeneder

回答

1

只是產生一個隨機數,並與您的網址,你得到所需的結果通過

e.g:

INT randomNumber1 = 1 + arc4random()%9; NSString * rstr = [NSString stringWithFormat:@「%d」,randomNumber1];

NSString *address = @"http://www.socialfactory.net/client-app/photovote/get_data.php"; 
NSString * nstr=[NSString stringWithFormat:@"%@?t=%@",address,rstr]; 
//NSURLRequest *theRequest=nil; 
NSURLRequest * theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:nstr]]; 
NSURLResponse *resp = nil; 
NSError *err = nil; 
+0

這是一個想法,我也是這樣做的,但這不是一個好的解決方案 – Ploetzeneder

1

也許你的模擬器和iPhone有不同的proxie設置。檢查這個或試圖與​​政策,這也忽略了中間說法。 See the docs here.

+0

不幸的是NSURLRequestReloadIgnoringLocalAndRemoteCacheData沒有實現,至少在iOS v6中是這樣的 –