android和iOS中打包html5

目前有一个项目想使用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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值