我正在开发免费应用程序,并有2个图像(一个透明覆盖层)作为背景。我将每月从我的网络中更改这两个图像。图像更新过程,但应用程序如何知道图像是否在网络上发生了变化?当启动应用程序,我要实现以下目标:启动应用程序 从网络更新iOS应用程序
- 支票可用于图片的更新,本地存储,作为背景使用
- 如果没有新的可用的图像,使用默认
- 启动应用程序
有人可以指向比较/ web请求过程的正确方向吗?
这是我到目前为止有:
viewDidLoad方法
self.imageData = [[NSMutableData alloc]init];
[NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.blahblah.com/newImage.jpg"]]delegate:self];
休息代码:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
self.length = [response expectedContentLength];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[self.imageData appendData:data];
float progress = (float)[imageData length]/(float)self.length;
[self.progressView setProgress:progress animated:YES];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"didFailWithError");
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
UIImage *img = [UIImage imageWithData:self.imageData];
self.backgroundImageView.image = img;
[self saveLocally:self.imageData];
}
// save
- (void)saveLocally:(NSData *)imgData
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSDate *aDate = [NSDate date];
NSTimeInterval interval = [aDate timeIntervalSince1970];
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d.jpeg",(int)interval]];
[imgData writeToFile:localFilePath atomically:YES];
}
谢谢您的时间!
谢谢迈克尔,我没有上传.txt文件,只有当内容改变时下载图像 – Alessign