iPhone App更新。 “createSymbolicLinkAtPath”发布了吗?

时间:2011-07-21 06:23:16

标签: ios

我正在使用iPhoneApp的符号链接。

NSString* js_path = [[NSBundle mainBundle] pathForResource:@"js" ofType:nil];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
if (js_path != nil) {
    NSFileManager *fm = [NSFileManager defaultManager];
    NSString* move_js_path = [NSString stringWithFormat:@"%@/js",  [paths objectAtIndex:0]];
    NSError *error; 
    if ([fm createSymbolicLinkAtPath:move_js_path withDestinationPath:js_path error:&error]) {
    } else {}
}

我更新了应用程序。之后无法读取文件。

但是,在删除应用程序一次后,可以通过重新安装来读取该文件。

此代码中是否存在问题?

1 个答案:

答案 0 :(得分:0)

如果有人对此感到疑惑,原因是应用程序移动目录每次更新时,解决方案可能是使用相对路径捆绑包位于/ var / mobile / Applications / [更改每次更新的唯一ID] / app .app而文档目录位于/ var / mobile / Applications / [更改每次更新的唯一ID] / Documents,因此如果它使用类似../[bundlepath lastPathComponent] /那么从Documents到bundle的符号链接将始终有效文件

从运行时获得的目录中建立相对性而不是对其进行硬编码是一个好主意,这将使这些相对路径在未来发生变化。

相关问题