android和iOS中打包html5

来源:互联网 发布:手机淘宝店铺怎么收藏 编辑:程序博客网 时间:2024/06/08 07:24

目前有一个项目想使用html5实现业务逻辑,同时发布成android和iOS 移动app,这个涉及到如何将这些html、图片、js打包进app并在webview中装载html。下面是具体细节:

一、android打包html5

      将html相关的代码拷贝到assets目录下,如下图所示:

     


  那么如何使用呢?如下所示即可访问index.html,使用WebView打开即可。

   private String url = "file:///android_asset/www/index.html";


二、iOS打包html5

    将html相关的代码拷贝到一个目录(如www),然后将该目录重命名为www.bundle,并拖放到xcode工程中。如下图所示:

    

    如何使用这个呢?如下所示代码可以访问index.html:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    // Override point for customization after application launch.    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    self.window.backgroundColor = [UIColor whiteColor];    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];        NSString  *bundlePath = [[ NSBundle   mainBundle ]. resourcePath   stringByAppendingPathComponent : @"www.bundle" ];    NSBundle  *bundle = [ NSBundle   bundleWithPath :bundlePath];    NSString* path = [bundle pathForResource:@"index" ofType:@"html"];        ZZQWebViewController *webView = [[ZZQWebViewController alloc]init];    webView.url = path;    webView.htmlStr = @"";    webView.title = @"";        self.window.rootViewController = webView;    [self.window makeKeyAndVisible];        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;        return YES;}



0 0
原创粉丝点击