2012-07-23 63 views
0

我有一个文件,包含在我想要覆盖的XCode项目中。该文件在名为Book写入XCode项目目录中的文件

的目录中名为Introduction.html在屏幕截图中,您可以看到它在目录中的位置以及我写入该目录的各种尝试。

enter image description here

任何帮助将是巨大的感谢!

编辑我的代码是不是在图片是可读:

//Atempt 1 
NSString *myString = [mutableArray objectAtIndex:0]; 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"/book/Introduction.html"]; 
[myString writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:&error]; 

//Attempt 2 
[myString writeToFile:@"/book/Introduction.html" atomically:NO encoding:NSUTF8StringEncoding error:&error]; 

//Attempt 3 
NSArray *paths2 = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); 
NSString *docDir = [paths2 objectAtIndex: 0]; 
NSString *docFile = [docDir stringByAppendingPathComponent: @"book/Introduction.html"];  
[myString writeToFile: docFile atomically:NO encoding:NSUTF8StringEncoding error:&error]; 


//Attempt 4 
NSFileHandle *file; 
NSMutableData *data; 
const char *bytestring = "black dog";  
data = [NSMutableData dataWithBytes:bytestring 
          length:strlen(bytestring)]; 
file = [NSFileHandle fileHandleForUpdatingAtPath: 
     @"book/Introduction.html"]; 
if (file == nil) 
    NSLog(@"Failed to open file"); 
[file seekToFileOffset: 10]; 
[file writeData: data]; 
[file closeFile]; 
[file release]; 

回答

0

itgiawa,

就我读过的文档,文件,“在我的XCode项目”不能被覆盖,因为iOS中的沙盒机制不允许您的应用访问此空间。我记得阅读指令“如果您需要覆盖您的应用程序随附的数据,将它们复制到Documents目录并覆盖副本。”

所以我会说你的尝试1接近最接近的事实,因为你需要首先将你的资源包中的文件复制到Documents目录中。

Regards,nobi