如何更改PhoneGap 1.x中的起始页面 [英] How to change start page in PhoneGap 1.x

查看:108
本文介绍了如何更改PhoneGap 1.x中的起始页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过下载更新包并覆盖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.

推荐答案

我能够通过覆盖 +(NSString *)wwwFolderName 来解决这个问题。 +(NSString *)pathForResource:(NSString *)resourcepath 我相信通过覆盖 +(NSString *)pathForResource:(NSString *)resourcepath I可能会遇到PhoneGap其他部分的一些问题。

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];
}

这篇关于如何更改PhoneGap 1.x中的起始页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆