简体   繁体   English

从Web服务器更新支持文件

[英]Update Supporting Files from Web Server

I am writing an IPhone application in witch I downloaded files and photos locally in the Supporting Files folder ( in the right panel of xcode ), these files are downloaded also in a web server, what I want is that if the application detect that these files are updated in the web server , it replace them with the new content in the Supporting Files I used 我正在用Iphone编写一个iPhone应用程序,我在Supporting Files夹(在xcode的右面板中)本地下载了文件和照片,这些文件也在Web服务器中下载了,我想要的是,如果应用程序检测到这些文件已在网络服务器中更新,它将替换为我使用的Supporting Files的新内容

NSArray* pathArray = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory,NSUserDomainMask, YES);  
documentsDirectory = [pathArray objectAtIndex:0];
NSString* localFile = [documentsDirectory stringByAppendingPathComponent:@"test.txt"];
[data writeToFile:localFile options:NSDataWritingAtomic  error:&error];

the code works well but the problem is that it replaces content of files in 该代码可以很好地工作,但是问题是它替换了
Library/Application Support folder and not the Supporting Files so when I do : Library/Application Support文件夹而不是Supporting Files因此在执行以下操作时:

NSBundle *thisBundle = [NSBundle mainBundle];
NSString *TextURL = [thisBundle pathForResource:@"test" ofType:@"txt"];
NSURL *instructionsURL = [NSURL fileURLWithPath:TextURL];
NSString *TextString = [NSString stringWithContentsOfURL:instructionsURL];
mayText.text = TextString;  

the old content is displayed and not the updated one How can I change my code to replace files in Supporting files directory every time Application Support files are changed ? 显示的是旧内容,而不是更新的内容。每次更改应用程序支持文件时,如何更改代码以替换支持文件目录中的文件? And what is the difference between these two folders? 这两个文件夹有什么区别? Thank you. 谢谢。

You can't. 你不能 iOS Apps on the device are signed, changing the bundle's content would break that signing. 设备上的iOS应用已签名,更改捆绑内容将破坏该签名。 And as all files that are managed by Xcode and added to a target go to the bundle, they must not be changed. 而且,由Xcode管理并添加到目标的所有文件都进入捆绑包,因此不得更改它们。

Instead download the files to a sandbox directory, such as Documents and access it there. 而是将文件下载到沙箱目录(例如“文档”)并在那里访问。

Also note that Supporting Files iin Xcode is not a directory but a group. 另请注意,Xcode中的Supporting Files不是目录而是一个组。 It juste groups it content inside the Xcode project but does not organize the files in a directory on file system level. 它只是将其内容分组在Xcode项目中,但不将文件组织在文件系统级别的目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM