我正在尝试通过下载更新包并覆盖PhoneGap项目的www文件来更新PhoneGap项目的Web文件。问题是www文件似乎存储在包中,而不是存储在文档目录中。我可以在启动时将这些文件复制到文档目录中,但我仍然不知道如何告诉PhoneGap使用文档目录中的index.html文件而不是原始的www目录。
答案 0 :(得分:1)
我能够通过覆盖+(NSString*)wwwFolderName
和+ (NSString*) pathForResource:(NSString*)resourcepath
来解决此问题。我相信通过覆盖+ (NSString*) pathForResource:(NSString*)resourcepath
我可能会遇到PhoneGap其他部分的一些问题。
+(NSString*)wwwFolderName {
return [NSString stringWithFormat:@"%@/www",[super applicationDocumentsDirectory]];
}
+ (NSString*) pathForResource:(NSString*)resourcepath
{
NSBundle * mainBundle = [NSBundle mainBundle];
NSMutableArray *directoryParts = [NSMutableArray arrayWithArray:[resourcepath componentsSeparatedByString:@"/"]];
NSString *filename = [directoryParts lastObject];
[directoryParts removeLastObject];
NSString* directoryPartsJoined =[directoryParts componentsJoinedByString:@"/"];
NSString* directoryStr = [self wwwFolderName];
if ([directoryPartsJoined length] > 0) {
directoryStr = [NSString stringWithFormat:@"%@/%@", [self wwwFolderName], [directoryParts componentsJoinedByString:@"/"]];
}
if (![[self wwwFolderName] isEqualToString:@"www"]) {
return [NSString stringWithFormat:@"%@/%@",[self wwwFolderName],[self startPage]];
}
return [mainBundle pathForResource:filename
ofType:@""
inDirectory:directoryStr];
}