当我打电话
-(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,在模拟器上每次都会从互联网上加载String。但是在设备上,它会缓存字符串,所以即使http://demo.komexa.com/sicherungsbereich.xml的内容发生了变化(你可以通过调用{ {3}})String不会自动重新加载新数据。
你有想法吗?
由于格式问题,我在此处上传了代码: http://demo.komexa.com
答案 0 :(得分:1)
也许你的模拟器和iPhone有不同的代理设置。选中此项或尝试使用NSURLRequestReloadIgnoringLocalAndRemoteCacheData
政策,该政策也会忽略中间广告。 See the docs here.
答案 1 :(得分: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;