3

我的应用程序非常简单。我有一些带有 html 文件名的 plist。当用户选择一行时,webview 会加载该 html 文件及其内容。我很好奇如何处理应用程序更新?例如:我有一个新的更新的 html 文件,其中包含更正,我希望用户通过单击应用程序中的按钮来下载该文件。我希望将旧文件(html)替换为新文件。有没有办法做到这一点?不太确定从哪里开始,希望有人能指出我正确的方向。我假设,没有办法更新 plist,我必须从 plist 切换到数据库,但问题仍然存在,如何让应用程序下载新文件并替换旧文件?

谢谢

只是为了详细说明一下。

我想我试图找出在我的应用程序中完成更新的正确方法。我的 html 文件在应用程序中,我假设我可能让应用程序最初连接到互联网并下载最新的内容文件(html、plist),将它们放入文档文件夹,然后更新我的主屏幕 plist 文件?这是正确的思路吗?

我不希望该应用程序仅适用于互联网,需要这些 html 文件可以离线使用。

4

4 回答 4

0

The answer is exactly what you described.

My most common train is to check for the existence in documents, add them from the bundle if they are not there.

use them, and download new ones in the background. (if the internet is available). replace the old ones with the new ones in the event a successful download happens.

And set a timeout of some type so you dont download a new one every second.

I like a day for my timeout.

and implement a way to check the version with the server. (MD5 Hash and filesize is a good not to mention small comparison)

Good luck

于 2012-06-22T23:28:11.937 回答
0

正如许多人建议的那样,我想我的计划是从网上下载内容,将其保存在库文件夹中,然后从那里加载内容。在应用程序中,我将有一个更新按钮,只要用户选择,它就会连接到服务器并更新内容。在 apple.com 找到示例代码(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;
}
于 2012-06-22T23:13:54.253 回答
0

如果你能得到新的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];
于 2012-06-21T03:36:57.063 回答
0

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

于 2012-06-21T03:27:43.213 回答