如何更新IOS中的应用程序文件(html)?

我的应用程序非常简单。 我有几个plists文件名称的HTML文件。 当用户select一行时,webview加载该HTML文件的内容。 我好奇如何处理应用程序更新? 例如:我有一个新的更新的HTML文件,更正,我希望用户通过单击应用程序中的button下载。 我想旧的文件(HTML)被replace为一个新的。 有没有办法做到这一点? 不知道从哪里开始,希望有人能指出我正确的方向。 我假设,将没有办法更新plist,我将不得不从plist切换到数据库,但问题仍然存在,我怎么得到应用程序下载新的文件,并取代旧的?

谢谢

多说一点。

我想我试图找出正确的方法来完成我的应用程序更新。 我的HTML文件是在应用程序内,即时通讯假设我可能有应用程序初始化连接到互联网和下载最新的内容文件(html,plists),将它们放到文档文件夹,然后更新我的主屏幕plist文件? 这是正确的思路吗?

我不希望应用程序只能上网,需要这些HTML文件脱机。

您可以将您的HTML文件存储在外部服务器上。 并改变你的应用程序从你的外部服务器加载HTML文件,而不是从你的应用程序包。 所以如果你需要更新任何HTML文件的内容,你可以在你的服务器上进行。

如果你能得到新的html文件名,你可以直接写入你的plist文件。

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"settings.plist"]; NSMutableDictionary* newValueDict=[[NSMutableDictionary alloc]initWithContentsOfFile:docPath]; [newValueDict setObject:newHtmlPageValue forKey:@"myHtmlPage"]; [newValueDict writeToFile:docPath atomically:NO]; [newValueDict release]; 

许多人build议,我想我的计划是从网上下载内容,将其保存在库文件夹中,然后从那里加载内容。 在应用程序内,我将有更新button,每当用户select将连接到服务器和更新内容。 在apple.com上find示例代码( https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html

将稍微调整,它应该工作正常,这也可以帮助,如果试图下载多个文件。 在iphone应用程序中下载多个文件(目标c)

 - (IBAction)down { // Create the request. NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://abc.com/missing.html"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; // create the connection with the request // and start loading the data NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; NSString *msg; if (theConnection) { // Create the NSMutableData to hold the received data. // receivedData is an instance variable declared elsewhere. receivedData = [[NSMutableData data] retain]; } else { // Inform the user that the connection failed. } } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { // This method is called when the server has determined that it // has enough information to create the NSURLResponse. // It can be called multiple times, for example in the case of a // redirect, so each time we reset the data. // receivedData is an instance variable declared elsewhere. [receivedData setLength:0]; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { // Append the new data to receivedData. //You can also use the connection:didReceiveData: method to provide an indication of the connection's progress to the user. // receivedData is an instance variable declared elsewhere. NSString *msg = [NSString stringWithFormat:@"data %@",data,nil ]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"-download-" message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; [alert show]; [alert release]; //NSLog ([[NSString alloc] initWithFormat:@"The value: %d object: %@\n", alphArray.count, [alphArray objectAtIndex:1.1],nil]); NSString *string = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; NSLog(@"the data %@",string); NSString *libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *filePath = [libraryPath stringByAppendingPathComponent:@"Missing.html"]; NSLog(@"Full path: %@", filePath); //NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //write data to files [data writeToFile:filePath atomically:YES]; [receivedData appendData:data]; } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { // release the connection, and the data object [connection release]; // receivedData is declared as a method instance elsewhere [receivedData release]; // inform the user NSLog(@"Connection failed! Error - %@ %@", [error localizedDescription], [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]); } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { // do something with the data // receivedData is declared as a method instance elsewhere NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]); // release the connection, and the data object [connection release]; [receivedData release]; } -(NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse { NSCachedURLResponse *newCachedResponse = cachedResponse; if ([[[[cachedResponse response] URL] scheme] isEqual:@"https"]) { newCachedResponse = nil; } else { NSDictionary *newUserInfo; newUserInfo = [NSDictionary dictionaryWithObject:[NSDate date] forKey:@"Cached Date"]; newCachedResponse = [[[NSCachedURLResponse alloc] initWithResponse:[cachedResponse response] data:[cachedResponse data] userInfo:newUserInfo storagePolicy:[cachedResponse storagePolicy]] autorelease]; NSLog(@"Succeeded! Receive use:%@",newUserInfo); } NSLog(@"Succeeded! Received %@ - use:%@",newCachedResponse); return newCachedResponse; } 

答案正是你所描述的。

我最常见的火车是检查文件中是否存在,如果不在那里,则从包中join。

使用它们,并在后台下载新的。 (如果互联网可用)。 在发生成功下载的情况下,用新的replace旧的。

并设置一些types的超时,所以你不要每秒下载一个新的。

我喜欢我的超时一天。

并实现一种方式来检查与服务器的版本。 (MD5哈希和文件大小是一个很好的,不要说小比较)

祝你好运