【问题标题】:How to change start page in PhoneGap 1.x如何在 PhoneGap 1.x 中更改起始页
【发布时间】:2012-01-31 20:06:37
【问题描述】:

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

【问题讨论】:

    标签: iphone ios ipad cordova


    【解决方案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];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-01
      相关资源
      最近更新 更多