Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在IOS中更新应用程序文件(html)?_Javascript_Objective C_Ios_Html - Fatal编程技术网

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

Javascript 如何在IOS中更新应用程序文件(html)?,javascript,objective-c,ios,html,Javascript,Objective C,Ios,Html,我的应用程序非常简单。我有几个文件名为html文件的plist。当用户选择一行时,webview将加载该html文件及其内容。我很好奇如何处理应用程序更新?例如:我有一个新的更新的html文件,带有更正,我希望用户通过单击应用程序中的按钮下载该文件。我想旧的文件(html)被一个新的替换。有办法做到这一点吗?不确定从哪里开始,希望有人能给我指出正确的方向。我假设,没有办法更新plist,我必须从plist切换到数据库,但问题仍然存在,我如何让应用程序下载新文件并替换旧文件 多谢各位 再详细说明一

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

多谢各位

再详细说明一下

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


我不希望应用程序仅在互联网上运行,需要那些html文件离线可用。

您可以将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];

正如许多人建议的那样,我想我的计划是从网上下载内容,保存在library文件夹中,然后从那里加载内容。在应用程序中,我将有一个更新按钮,每当用户选择时,它将连接到服务器并更新内容。在apple.com()上找到示例代码

将调整一点,它应该工作良好,这也可能有助于如果试图下载多个文件


答案正是你所描述的

我最常用的训练是检查文档中是否存在,如果不存在,则从包中添加它们

使用它们,并在后台下载新的。(如果互联网可用)。 如果下载成功,用新的替换旧的

并设置某种类型的超时,这样你就不会每秒下载一个新的

我喜欢休息一天

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


祝你好运

只需发送一个新版本的应用程序,其中包含更新的plist和HTML文件?HTML文件存储在哪里?在应用程序本身内(在这种情况下,@Devraj的评论是有效的),或者它们是由应用程序下载并存储在其他地方(例如“文档”目录中),还是从远程服务器托管和查看?或者?如果它们存储在远程服务器上,只需更新远程服务器上的文件即可。我知道我可以发布新版本的应用程序,但审批过程大约需要7天。如果我必须纠正一个小的打字错误,我希望避免这种情况。另一方面,因为我并没有真正改变程序,所以只需将所有新的html文件推送到应用程序并更新plist引用就很有用了。在远程服务器上托管文件并让用户访问这些文件会很容易,但当用户没有互联网连接和应用程序的全部用途时,问题就出现了,即使没有互联网连接,数据也是可用的。HTML文件存储在应用程序中,但现在我想起来了,将它们存储在documents文件夹中是否有意义?只需将应用程序连接到internet即可下载最新内容。感谢所有的回复。在远程服务器上托管文件并让用户访问它们会很容易,但是当用户没有internet连接时,问题就会出现,并且应用程序的整个用途是,即使没有internet连接,也需要数据可用。当然。您对原始问题的编辑使问题更加清晰,而且似乎是正确的路径。谢谢,您将文件保存在库中还是文档文件夹中?我将文件放在字典文件夹中的文件夹中。只要确保您有办法使这些文件过期,并覆盖旧文件即可。如果每次都添加新文件,那么最终会填满设备,这是一种糟糕的做法。是的,我知道,我的计划是在下载文件时立即覆盖库文件夹中的旧文件。我建议将它们下载到一个地方。然后在下载成功后替换它们。从我的错误中吸取教训。我必须重新编写代码,因为我这样做了。我的项目是图像,但结果是一样的。下载失败并覆盖文件,您将一无所获-
- (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;
}