我正在開發免費應用程序,並有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