如何更改 PhoneGap 1.x 中的起始页

发布于 2025-01-01 03:30:57 字数 171 浏览 0 评论 0原文

我正在尝试通过下载更新包并覆盖 PhoneGap 项目的 www 文件来更新 PhoneGap 项目的 Web 文件。问题在于 www 文件似乎存储在捆绑包中,而不是存储在文档目录中。我可以在启动时将这些文件复制到文档目录中,但我仍然不知道如何告诉PhoneGap使用文档目录中的index.html文件而不是原始的www目录。

I am trying to update the web files for a PhoneGap project by having it download an update package and overwrite the www files for the PhoneGap project. The problem is that the www files appear to be stored in the bundle and not in the documents directory. I can copy these files out to the documents directory on launch, but I am still unaware of how to tell PhoneGap to use the index.html file from the documents directory instead of the original www directory.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卖梦商人 2025-01-08 03:30:57

我能够通过覆盖 +(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];
}

I was able to solve this by overriding +(NSString*)wwwFolderName and + (NSString*) pathForResource:(NSString*)resourcepath I believe that by overriding + (NSString*) pathForResource:(NSString*)resourcepath I may run into some problems with other parts of 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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文